﻿using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public  class SteelTowerStructure
    {
        public static void DrawSteelTower(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope, System.Data.DataRow dr, string layerName = "H细线")
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 100;
            double hcSpan = double.Parse(dr["cross_brace_h_span"].ToString());
            hcSpan = hcSpan * 100;
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, topWidth * 0.5 * brslope), stpointLM.C2D(-topWidth * 0.5, -cushionH), ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -topWidth * 0.5 * brslope), stpointLM.C2D(topWidth * 0.5, -cushionH), ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, -cushionH), pt1, ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -cushionH), pt2, ref ext, layerName);
            int hcNum = (int)(twHeight / hcSpan);
            PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            for (int m = 1; m < hcNum; m++)
            {
                Point2d p1 = stpointLM.C2D(-topWidth * 0.5 - hcSpan * m * slope, -cushionH - hcSpan * m);
                Point2d p2 = stpointLM.C2D(topWidth * 0.5 + hcSpan * m * slope, -cushionH - hcSpan * m);
                PLPloter.AddLine(db, p1, p2, ref ext, layerName);
            }
        }

        public static void DrawGemstoneShapeSteelTower(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope, System.Data.DataRow dr, string layerName = "H细线")
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 100;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, topWidth * 0.5 * brslope), stpointLM.C2D(-topWidth * 0.5, -cushionH), ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -topWidth * 0.5 * brslope), stpointLM.C2D(topWidth * 0.5, -cushionH), ref ext, layerName);
            Line lineL = PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, -cushionH), pt1, ref ext, layerName);
            Line lineR = PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -cushionH), pt2, ref ext, layerName);
            PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            double h = twHeight * 0.01 - cushionH * 0.01;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                //double htemp = 0;
                //for (int i = 0; i < segmentList.Count; i++)
                //{
                //    htemp += segmentList[i];
                //    double seg = h - (htemp - segmentList[i]);
                //    if (htemp > h)
                //    {
                //        if (seg > 0)
                //        {
                //            segmentLst.Add(seg);
                //            h = seg + (htemp - segmentList[i]);
                //        }
                //        break;
                //    }
                //    else
                //    {
                //        segmentLst.Add(segmentList[i]);
                //    }
                //}
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            //segmentLst.Add(seg);
                            //h = seg + (htemp - segmentList[i]);
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                //segmentLst.remove(segmentLst.size()-1);
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - (htemp - segmentList[i]) + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                            segmentLst.Add(segmentList[i]);
                    }
                }
            }
            #endregion

            //double slopeW = double.Parse(dr["slope_w"].ToString()); ;// 0.025;
            //double slopeL = double.Parse(dr["slope_l"].ToString());//0.125*0.5;

            Point2d stPt = stpointLM.C2D(0, -cushionH);
            double ycurT = 0;
            double ycurB = 0;

            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 100;
                ycurT = ycurB - seg * 100;
                // 顶部端点
                Line lineT = new Line(stPt.C3D(-topWidth * 0.5, -ycurT), stPt.C3D(topWidth * 0.5, -ycurT));
                Line lineB = new Line(stPt.C3D(-topWidth * 0.5, -ycurB), stPt.C3D(topWidth * 0.5, -ycurB));

                Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
                Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);
                Point3d ptLB = MathExtensions.GetIntersection(lineL, lineB);
                Point3d ptRB = MathExtensions.GetIntersection(lineR, lineB);

                if (i == 3)
                {
                    Point2d styPt1 = stpointLM.C2D(-topWidth * 2.5, topWidth * 2.5 * brslope);
                    Point2d styPt2 = stpointLM.C2D(topWidth * 2.5, -topWidth * 2.5 * brslope);

                    PLPloter.AddLine(db, ptLT.C2D(), styPt1, ref ext, layerName);
                    PLPloter.AddLine(db, ptRT.C2D(), styPt2, ref ext, layerName);
                }

                double scaleTen = 1 / 2.000;

                Point2d ptTMid = stPt.C2D(0, -ycurT);
                Point2d ptBMid = stPt.C2D(0, -ycurB);
                if (seg <= max)
                {
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                }
                else  //if (seg > min && seg <= max)
                {
                    scaleTen = 1 / 2.000;
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                    Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                    Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                    Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                    Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                    PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);
                }
                //else
                //{
                //    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                //    scaleTen = 1 / 3.000;
                //    Point3d ptMainL = GeTools.DivPoint(ptLT, ptLB,3);
                //    Point3d ptMainR = GeTools.DivPoint(ptRT, ptRB,3);
                //    Point3d ptL = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3);
                //    Point3d ptR = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3);
                //    PLPloter.AddLine(db, ptMainL.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR.C2D(), ptR.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptRT.C2D(), ptR.C2D(), ref ext, layerName);
                //    scaleTen = 2 / 3.000;
                //    Point3d ptMainL2 = GeTools.DivPoint(ptLT, ptLB, 3, true);
                //    Point3d ptMainR2 = GeTools.DivPoint(ptRT, ptRB, 3, true);
                //    Point3d ptL2 = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3, true);
                //    Point3d ptR2 = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3, true);

                //    PLPloter.AddLine(db, ptMainL2.C2D(), ptL2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR2.C2D(), ptR2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptL2.C2D(), ptMainL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptR2.C2D(), ptMainR.C2D(), ref ext, layerName);
                //}

            }
        }

        public static void DrawYGemstoneShapeSteelTower(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope, System.Data.DataRow dr, string layerName = "H细线")
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 100;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight = double.Parse(dr["yshape_height"].ToString()) * 100;
            double ySegLen = double.Parse(dr["yshape_segment_length"].ToString()) * 100;
            int segNum = int.Parse(dr["yshape_segment_number"].ToString());
            string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();

            String[] yHStr = yBHeightLayout.Split('+');
            double hy1 = 3 * 100, hy2 = 2.6 * 100;
            if (yHStr.Length > 0)
            {
                hy1 = Double.Parse(yHStr[0]) * 100;
                if (yHStr.Length > 1)
                    hy2 = Double.Parse(yHStr[1]) * 100;
            }

            //double slopeW = double.Parse(dr["slope_w"].ToString()); ;// 0.025;
            //double slopeL = double.Parse(dr["slope_l"].ToString());//0.125*0.5;
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            //PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, topWidth * 0.5 * brslope), stpointLM.C2D(-topWidth * 0.5, -cushionH), ref ext, layerName);
            //PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -topWidth * 0.5 * brslope), stpointLM.C2D(topWidth * 0.5, -cushionH), ref ext, layerName);


            double h = twHeight * 0.01 - yHeight * 0.01;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            //segmentLst.Add(seg);
                            //h = seg + (htemp - segmentList[i]);
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                //segmentLst.remove(segmentLst.size()-1);
                                //seg = h - (htemp - segmentList[i]);
                                //segmentLst.Add(seg);
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - (htemp - segmentList[i]) + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                            segmentLst.Add(segmentList[i]);
                    }
                }
            }
            #endregion


            #region Y形
            Point2d styPt1 = stpointLM.C2D(-topWidth * 4.5, topWidth * 4.5 * brslope);
            Point2d styPt2 = stpointLM.C2D(topWidth * 4.5, -topWidth * 4.5 * brslope);
            //宝石底部宽度
            double btWidth = topWidth + (yHeight - cushionH) * slope * 2;
            Point2d yPt1 = stpointLM.C2D(-btWidth * 0.5, -yHeight);
            Point2d yPt2 = stpointLM.C2D(btWidth * 0.5, -yHeight);
            Point2d ybtMidPt = stpointLM.C2D(0, -yHeight + hy1 + hy2);
            Point2d ybMidPt = stpointLM.C2D(0, -yHeight + hy1);
            //外轮廓
            PLPloter.AddLine(db, styPt1.C2D(), yPt1, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), yPt2, ref ext, layerName);
            //内轮廓
            PLPloter.AddLine(db, styPt1.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), ybtMidPt, ref ext, layerName);
            //Y搭接
            PLPloter.AddLine(db, ybMidPt.C2D(), yPt1, ref ext, layerName);
            PLPloter.AddLine(db, ybMidPt.C2D(), yPt2, ref ext, layerName);
            PLPloter.AddLine(db, ybMidPt.C2D(), ybtMidPt, ref ext, layerName);

            Point3d yPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), segNum + 1);
            Point3d yPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), segNum + 1);


            PLPloter.AddLine(db, yPtL.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPtR.C2D(), ybtMidPt, ref ext, layerName);

            PLPloter.AddLine(db, yPtL.C2D(), ybMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPtR.C2D(), ybMidPt, ref ext, layerName);

            Point3d yLastPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), segNum + 1);
            Point3d yLastPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), segNum + 1);
            //Y悬臂
            for (int i = 1; i <= segNum; i++)
            {
                Point3d yLOutPt = GeTools.CalPoint(yPt1.C3D(), styPt1.C3D(), (i + 1) / (segNum + 1.000));
                Point3d yLInnerPt = GeTools.CalPoint(ybtMidPt.C3D(), styPt1.C3D(), (i) / (segNum * 1000 * 0.001));

                Point3d yROutPt = GeTools.CalPoint(yPt2.C3D(), styPt2.C3D(), (i + 1) / (segNum + 1.000));
                Point3d yRInnerPt = GeTools.CalPoint(ybtMidPt.C3D(), styPt2.C3D(), (i) / (segNum * 1000 * 0.001));


                PLPloter.AddLine(db, yLOutPt.C2D(), yLInnerPt.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yROutPt.C2D(), yRInnerPt.C2D(), ref ext, layerName);



                PLPloter.AddLine(db, yLastPtL.C2D(), yLInnerPt.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yLastPtR.C2D(), yRInnerPt.C2D(), ref ext, layerName);
                yLastPtL = yLOutPt;
                yLastPtR = yROutPt;
            }
            #endregion

            #region 钢塔下部宝石结构
            topWidth = topWidth + (yHeight - cushionH) * slope * 2;
            Point2d stPt = stpointLM.C2D(0, -yHeight);
            Line lineL = PLPloter.AddLine(db, stPt.C2D(-topWidth * 0.5, 0), pt1, ref ext, layerName);
            Line lineR = PLPloter.AddLine(db, stPt.C2D(topWidth * 0.5, 0), pt2, ref ext, layerName);
            PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            double ycurT = 0;
            double ycurB = 0;

            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 100;
                ycurT = ycurB - seg * 100;
                // 顶部端点
                Line lineT = new Line(stPt.C3D(-topWidth * 0.5, -ycurT), stPt.C3D(topWidth * 0.5, -ycurT));
                Line lineB = new Line(stPt.C3D(-topWidth * 0.5, -ycurB), stPt.C3D(topWidth * 0.5, -ycurB));

                Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
                Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);
                Point3d ptLB = MathExtensions.GetIntersection(lineL, lineB);
                Point3d ptRB = MathExtensions.GetIntersection(lineR, lineB);
                double scaleTen = 1 / 2.000;

                Point2d ptTMid = stPt.C2D(0, -ycurT);
                Point2d ptBMid = stPt.C2D(0, -ycurB);
                if (seg <= max)
                {
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                }
                else
                {
                    scaleTen = 1 / 2.000;
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                    Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                    Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                    Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                    Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                    PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);
                }
                //else
                //{
                //    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                //    scaleTen = 1 / 3.000;
                //    Point3d ptMainL = GeTools.DivPoint(ptLT, ptLB, 3);
                //    Point3d ptMainR = GeTools.DivPoint(ptRT, ptRB, 3);
                //    Point3d ptL = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3);
                //    Point3d ptR = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3);
                //    PLPloter.AddLine(db, ptMainL.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR.C2D(), ptR.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptRT.C2D(), ptR.C2D(), ref ext, layerName);
                //    scaleTen = 2 / 3.000;
                //    Point3d ptMainL2 = GeTools.DivPoint(ptLT, ptLB, 3, true);
                //    Point3d ptMainR2 = GeTools.DivPoint(ptRT, ptRB, 3, true);
                //    Point3d ptL2 = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3, true);
                //    Point3d ptR2 = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3, true);

                //    PLPloter.AddLine(db, ptMainL2.C2D(), ptL2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR2.C2D(), ptR2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptL2.C2D(), ptMainL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptR2.C2D(), ptMainR.C2D(), ref ext, layerName);
                //}

            }
            #endregion
        }

        #region Y形
        public static void DrawYGemstoneShapeElevation(Database db, Point2d stpointLM, ref Extents2d ext,double topWidth, double slope, double brslope, System.Data.DataRow dr, double pierH, string layerName = "H细线",double scale=200)
        {
          
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight = double.Parse(dr["yshape_height"].ToString()) * 1000;
            double ySegLen = double.Parse(dr["yshape_segment_length"].ToString()) * 1000;
            int segNum = int.Parse(dr["yshape_segment_number"].ToString());
           

            string maninDB = "Φ" + dr["yshape_main_diameter"].ToString()+ "×" + dr["yshape_main_thickness"].ToString();
            string braceDB = "Φ" + dr["yshape_brace_diameter"].ToString() + "×" + dr["yshape_brace_thickness"].ToString();
            string crossDB = "Φ" + dr["yshape_cross_diameter"].ToString() + "×" + dr["yshape_cross_thickness"].ToString();

            double bottomY = string.IsNullOrWhiteSpace(dr["bottom_y_length"].ToString()) ? 0 : double.Parse(dr["bottom_y_length"].ToString()) * 1000;

            string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();
            String[] yHStr = yBHeightLayout.Split('+');
            double hy1 = 3 * 1000, hy2 = 2.6 * 1000;
            if (yHStr.Length > 0)
            {
                hy1 = Double.Parse(yHStr[0]) * 1000;
                if (yHStr.Length > 1)
                    hy2 = Double.Parse(yHStr[1]) * 1000;
            }

            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
           

            #region Y形
            Point2d styPt1 = stpointLM.C2D(-topWidth * 4.5, topWidth * 4.5 * brslope);
            Point2d styPt2 = stpointLM.C2D(topWidth * 4.5, -topWidth * 4.5 * brslope);
            //宝石底部宽度
            double btWidth =bottomY>0? bottomY: Math.Round((topWidth + (yHeight - cushionH) * slope * 2), 1);
            Point2d yPt1 = stpointLM.C2D(-btWidth * 0.5, -yHeight);
            Point2d yPt2 = stpointLM.C2D(btWidth * 0.5, -yHeight);
            Point2d ybtMidPt = stpointLM.C2D(0, -yHeight + hy1 + hy2);
            //Point2d ybMidPt = stpointLM.C2D(0, -yHeight + hy1);
            //外轮廓
            PLPloter.AddLine(db, styPt1.C2D(), yPt1, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), yPt2, ref ext, layerName);
            PLPloter.AddLine(db, yPt1.C2D(), yPt2, ref ext, layerName);
            DimPloter.DimRot(db, styPt1.C3D(), styPt2.C3D(), styPt2.C3D(0, 10 * scale), ref ext, 0, scale, "", Unit.Millimeter, Unit.Millimeter);
            //DimPloter.DimAli(db, styPt1.C3D(), yPt1.C3D(), yPt1.C3D(-5*scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, styPt1.C3D(), styPt2.C3D(), styPt1.C3D(0,15 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, yPt1.C3D(), yPt2.C3D(), yPt2.C3D(0,-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //内轮廓
            PLPloter.AddLine(db, styPt1.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), ybtMidPt, ref ext, layerName);

            //DimPloter.DimAli(db, styPt1.C3D(), ybtMidPt.C3D(), ybtMidPt.C3D(5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //DimPloter.DimAli(db, styPt2.C3D(), ybtMidPt.C3D(), ybtMidPt.C3D(-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
           
            //Y搭接
            //PLPloter.AddLine(db, ybMidPt.C2D(), yPt1, ref ext, layerName);
            //PLPloter.AddLine(db, ybMidPt.C2D(), yPt2, ref ext, layerName);
            //PLPloter.AddLine(db, ybMidPt.C2D(), ybtMidPt, ref ext, layerName);
            //DimPloter.DimAli(db, yPt1.C3D(), ybMidPt.C3D(), ybMidPt.C3D(5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //DimPloter.DimAli(db, yPt2.C3D(), ybMidPt.C3D(), ybMidPt.C3D(-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //DimPloter.DimAli(db, ybMidPt.C3D(), ybtMidPt.C3D(), styPt1.C3D(0 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
            //DimPloter.DimAli(db, ybMidPt.C3D(0,-hy1), ybMidPt.C3D(), styPt1.C3D(0 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
            DimPloter.DimAli(db, stpointLM.C3D(), stpointLM.C3D(0, -yHeight), stpointLM.C3D(), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
            //DimPloter.DimAli(db, styPt1.C3D(), stpointLM.C3D(-topWidth * 4.5, -yHeight), styPt1.C3D(-10 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, styPt1.C3D(), yPt1.C3D(), styPt1.C3D(-10 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, styPt1.C3D(), ybtMidPt.C3D(), styPt1.C3D(8 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

            //DimPloter.DimAli(db, ybMidPt.C3D(), ybtMidPt.C3D(), styPt2.C3D(0 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
            //DimPloter.DimAli(db, ybMidPt.C3D(0, -hy1), ybMidPt.C3D(), styPt2.C3D(0 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
            //DimPloter.DimAli(db, stpointLM.C3D(), stpointLM.C3D(0, -yHeight), styPt2.C3D(10 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
            //DimPloter.DimAli(db, styPt2.C3D(), stpointLM.C3D(topWidth * 4.5, -yHeight), styPt2.C3D(10 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, styPt2.C3D(), yPt2.C3D(), styPt2.C3D(10 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, styPt2.C3D(), ybtMidPt.C3D(), styPt2.C3D(-8 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

            Point3d yPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), segNum + 1);
            Point3d yPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), segNum + 1);


            PLPloter.AddLine(db, yPtL.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPtR.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPt1.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPt2.C2D(), ybtMidPt, ref ext, layerName);
            //DimPloter.DimAli(db, yPtL.C3D(), ybtMidPt.C3D(), ybtMidPt.C3D(0,-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //DimPloter.DimAli(db, yPtR.C3D(), ybtMidPt.C3D(), ybtMidPt.C3D(0,-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

            //PLPloter.AddLine(db, yPtL.C2D(), ybMidPt, ref ext, layerName);
            //PLPloter.AddLine(db, yPtR.C2D(), ybMidPt, ref ext, layerName);
            //DimPloter.DimAli(db, yPtL.C3D(), ybMidPt.C3D(), ybMidPt.C3D(0,-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
            //DimPloter.DimAli(db, yPtR.C3D(), ybMidPt.C3D(), ybMidPt.C3D(0,-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);

            //DimPloter.DimRot(db, stpointLM.C3D(0, -yHeight), ybtMidPt.C3D(), styPt1.C3D(0 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //DimPloter.DimRot(db, stpointLM.C3D(0, -yHeight), ybtMidPt.C3D(), styPt2.C3D(0 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

            Point3d yLastPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), segNum + 1);
            Point3d yLastPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), segNum + 1);
            Point3d yLastPtInnerL = ybtMidPt.C3D();
            Point3d yLastPtInnerR = ybtMidPt.C3D();
            //DimPloter.DimRot(db, yLastPtL.C3D(), yPt1.C3D(), styPt1.C3D(-5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //DimPloter.DimRot(db, yLastPtR.C3D(), yPt2.C3D(), styPt2.C3D(5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, yLastPtL.C3D(), yPt1.C3D(), styPt1.C3D(-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            DimPloter.DimAli(db, yLastPtR.C3D(), yPt2.C3D(), styPt2.C3D(5 * scale), ref ext,  scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            //Y悬臂
            for (int i = 1; i <= segNum; i++)
            {
                Point3d yLOutPt = GeTools.CalPoint(yPt1.C3D(), styPt1.C3D(), (i + 1) / (segNum + 1.000));
                Point3d yLInnerPt = GeTools.CalPoint(ybtMidPt.C3D(), styPt1.C3D(), (i) / (segNum * 1000 * 0.001));

                Point3d yROutPt = GeTools.CalPoint(yPt2.C3D(), styPt2.C3D(), (i + 1) / (segNum + 1.000));
                Point3d yRInnerPt = GeTools.CalPoint(ybtMidPt.C3D(), styPt2.C3D(), (i) / (segNum * 1000 * 0.001));


                PLPloter.AddLine(db, yLOutPt.C2D(), yLInnerPt.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yROutPt.C2D(), yRInnerPt.C2D(), ref ext, layerName);
                //if (i < segNum)
                //{
                //    DimPloter.DimRot(db, yLOutPt.C3D(), yLInnerPt.C3D(), styPt1.C3D(-4 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                //    DimPloter.DimRot(db, yROutPt.C3D(), yRInnerPt.C3D(), styPt2.C3D(4 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                //}


                PLPloter.AddLine(db, yLastPtL.C2D(), yLInnerPt.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yLastPtR.C2D(), yRInnerPt.C2D(), ref ext, layerName);
                //DimPloter.DimRot(db, yLastPtL.C3D(), yLOutPt.C3D(), styPt1.C3D(-5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                //DimPloter.DimRot(db, yLastPtR.C3D(), yROutPt.C3D(), styPt2.C3D(5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                //DimPloter.DimRot(db, yLastPtInnerL.C3D(), yLInnerPt.C3D(), styPt1.C3D(0 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                //DimPloter.DimRot(db, yLastPtInnerR.C3D(), yRInnerPt.C3D(), styPt2.C3D(0 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                DimPloter.DimAli(db, yLastPtL.C3D(), yLOutPt.C3D(), styPt1.C3D(-5 * scale), ref ext,  scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                DimPloter.DimAli(db, yLastPtR.C3D(), yROutPt.C3D(), styPt2.C3D(5 * scale), ref ext,  scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                DimPloter.DimAli(db, yLastPtInnerL.C3D(), yLInnerPt.C3D(), styPt1.C3D(3 * scale), ref ext,  scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                DimPloter.DimAli(db, yLastPtInnerR.C3D(), yRInnerPt.C3D(), styPt2.C3D(-3 * scale), ref ext,  scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                if (i == segNum - 3)
                {
                    Point2d p1 = GeTools.MidPoint(yLastPtL.C3D(), yLInnerPt.C3D()).C2D();
                    DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(topWidth * 0.6 + 5 * scale, 7 * scale), p1.C2D(topWidth * 0.6 + 5 * scale, 7 * scale), braceDB, ref ext, scale);
                }
                if (i == segNum - 4)
                {
                    Point2d p1 = GeTools.MidPoint(yLOutPt.C3D(), yLInnerPt.C3D()).C2D();
                    DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(topWidth * 0.6 + 5 * scale, 10 * scale), p1.C2D(topWidth * 0.6 + 5 * scale, 10 * scale), crossDB, ref ext, scale);
                }
                yLastPtL = yLOutPt;
                yLastPtR = yROutPt;
                yLastPtInnerL = yLInnerPt;
                yLastPtInnerR = yRInnerPt;
            }
            Point2d p0 = GeTools.DivPoint(styPt1.C3D(), ybtMidPt.C3D(),4).C2D();
            DimPloter.AddMultiMLeader(db, p0.C2D(), p0.C2D(5* scale, 6* scale), p0.C2D(5 * scale,6 * scale), maninDB, ref ext, scale);

            #endregion

            double ang1 = Math.Atan(yHeight / topWidth * 4.5);
            double ang2 = Math.Atan((yHeight- hy1- hy2) / topWidth * 4.5);
            DimPloter.AddLeft2RightBJWithAng(db, "A", styPt1.C3D(-3*scale, 6*scale), ref ext, scale, 3, ang1, false);
         
            DimPloter.AddLeft2RightBJWithAng(db, "A", yPt1.C3D(-4 * scale, -5 * scale), ref ext, scale, 3, ang1, true);
            DimPloter.AddLeft2RightBJWithAng(db, "B", styPt1.C3D(3 * scale, 6 * scale), ref ext, scale, 3, ang2, false);
            DimPloter.AddLeft2RightBJWithAng(db, "B", ybtMidPt.C3D(-4*scale, -5 * scale), ref ext, scale, 3, ang2, true);

            DimPloter.AddLeft2RightBJWithAng(db, "C", styPt2.C3D(3 * scale, 6 * scale), ref ext, scale, 3, ang1, false);
            DimPloter.AddLeft2RightBJWithAng(db, "C", yPt2.C3D(3 * scale, -5 * scale), ref ext, scale, 3, ang1, true);
            DimPloter.AddLeft2RightBJWithAng(db, "D", styPt2.C3D(-3 * scale, 6 * scale), ref ext, scale, 3, ang2, false);
            DimPloter.AddLeft2RightBJWithAng(db, "D", ybtMidPt.C3D(3 * scale, -5 * scale), ref ext, scale, 3, ang2, true);
            double twHeight = pierH;
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            topWidth = topWidth + (yHeight - cushionH) * slope * 2;
            Point2d stPt = stpointLM.C2D(0, -yHeight);
            Line lineL = new Line(stPt.C3D(-topWidth * 0.5, 0), pt1.C3D());
            Line lineR = new Line(stPt.C3D(topWidth * 0.5, 0), pt2.C3D());

            // 顶部端点
            Line lineT = new Line(stPt.C3D(-topWidth * 0.5, -3*1000), stPt.C3D(topWidth * 0.5, -3 * 1000));

            Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
            Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);

            PLPloter.AddLine(db, stPt.C2D(-topWidth * 0.5, 0), ptLT.C2D(), ref ext, layerName);
            PLPloter.AddLine(db, stPt.C2D(topWidth * 0.5, 0), ptRT.C2D(), ref ext, layerName);
            PLPloter.CreateBreakLineP(db, ref ext, ptLT.C2D(-5 * scale), ptRT.C2D(5 * scale), scale * 0.5, "H细线");
        }

        //外轮廓
        public static void DrawYGemstoneShapeSide(Database db, Point2d stpointLM, ref Extents2d ext, double beamSegLength,double topWidth, double slope, double brslope, System.Data.DataRow dr,bool isLeft=true, string layerName = "H细线", double scale = 200)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight = double.Parse(dr["yshape_height"].ToString()) * 1000;
            double ySegLen = double.Parse(dr["yshape_segment_length"].ToString()) * 1000;
            int segNum = int.Parse(dr["yshape_segment_number"].ToString());
            string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();
            double bottomY = string.IsNullOrWhiteSpace(dr["bottom_y_width"].ToString()) ? 0 : double.Parse(dr["bottom_y_width"].ToString()) * 1000;

            String[] yHStr = yBHeightLayout.Split('+');
            double hy1 = 3 * 1000, hy2 = 2.6 * 1000;
            if (yHStr.Length > 0)
            {
                hy1 = Double.Parse(yHStr[0]) * 1000;
                if (yHStr.Length > 1)
                    hy2 = Double.Parse(yHStr[1]) * 1000;
            }

            #region Y形
            Point2d styPt1 = stpointLM.C2D(-topWidth * 0.5, beamSegLength * 4.5 * brslope);
            Point2d styPt2 = stpointLM.C2D(topWidth * 0.5, beamSegLength * 4.5 * brslope);
            //宝石底部宽度
            double btWidth = bottomY>0? bottomY: Math.Round((topWidth + (yHeight - cushionH) * slope * 2), 1);
            //Point3d stPt0 = Point3d.Origin.C3D(-beamSegLength * 0.5, beamSegLength * 4.5 * brslope, -topWidth * 0.5);
            Point3d stPt1 = Point3d.Origin.C3D(-beamSegLength * 4.5, -yHeight, -btWidth * 0.5);
            if (!isLeft)
            {
                styPt1 = stpointLM.C2D(-topWidth * 0.5, -beamSegLength * 4.5 * brslope);
                styPt2 = stpointLM.C2D(topWidth * 0.5, -beamSegLength * 4.5 * brslope);
                //stPt0 = Point3d.Origin.C3D(-beamSegLength * 0.5, -beamSegLength * 4.5 * brslope, -topWidth * 0.5);
            }
            DimPloter.AddMultiMLeader(db, styPt1.C2D(topWidth * 0.5), styPt1.C2D(topWidth * 0.5).C2D(2 * scale, 10 * scale), styPt1.C2D(topWidth * 0.5).C2D(2 * scale, 10 * scale), "钢主梁构件", ref ext, scale);
            //double lenS =Math.Round( MathExtensions.PointDistance(styPt1, stPt1),1);
            //double h = Math.Sqrt(Math.Pow(lenS, 2) - Math.Pow((btWidth-topWidth)*0.5, 2));
            Point2d yPt1 = stpointLM.C2D(-btWidth * 0.5, -yHeight);
            Point2d yPt2 = stpointLM.C2D(btWidth * 0.5, -yHeight);
      
            //轮廓
            PLPloter.AddLine(db, styPt1.C2D(), yPt1, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), yPt2, ref ext, layerName);
            //DimPloter.DimRot(db, styPt1.C3D(), yPt1.C3D(), yPt1.C3D(-5 * scale), ref ext,90, scale, "", Unit.Millimeter, Unit.Millimeter, 0);
            DimPloter.DimRot(db, styPt2.C3D(), yPt2.C3D(), yPt2.C3D(10 * scale), ref ext,90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            PLPloter.AddLine(db, styPt1.C2D(), styPt2, ref ext, layerName);
            PLPloter.AddLine(db, yPt1.C2D(), yPt2, ref ext, layerName);
            //DimPloter.DimAli(db, styPt1.C3D(), styPt2.C3D(), styPt2.C3D(0,5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 0);
         
            DimPloter.DimAli(db, yPt1.C3D(), yPt2.C3D(), yPt2.C3D(0,-5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

            Point3d yPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), segNum + 1);
            Point3d yPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), segNum + 1);

            Point3d yLastPtL = yPt1.C3D();
            Point3d yLastPtR = yPt2.C3D();
            //Y悬臂
            for (int i = 0; i <= segNum; i++)
            {
                Point3d yLOutPt = GeTools.CalPoint(yPt1.C3D(), styPt1.C3D(), (i + 1) / (segNum + 1.000));
                Point3d yROutPt = GeTools.CalPoint(yPt2.C3D(), styPt2.C3D(), (i + 1) / (segNum + 1.000));
                PLPloter.AddLine(db, yLOutPt.C2D(), yROutPt.C2D(), ref ext, layerName);
                if (isLeft)
                {
                    if (i%2==0)
                    {
                        PLPloter.AddLine(db, yLOutPt.C2D(), yLastPtR.C2D(), ref ext, layerName);
                    }
                    else
                    {
                        PLPloter.AddLine(db, yROutPt.C2D(), yLastPtL.C2D(), ref ext, layerName);
                    }
                }
                else
                {
                    if (i % 2 == 0)
                    {
                        PLPloter.AddLine(db, yROutPt.C2D(), yLastPtL.C2D(), ref ext, layerName);
                    }
                    else
                    {
                        PLPloter.AddLine(db, yLOutPt.C2D(), yLastPtR.C2D(), ref ext, layerName);
                    }
                }
             
                DimPloter.DimRot(db, yLastPtR.C3D(), yROutPt.C3D(), yPt2.C3D(5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                DimPloter.DimAli(db, yLOutPt.C3D(), yROutPt.C3D(), yROutPt.C3D(0, 5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

                yLastPtL = yLOutPt;
                yLastPtR = yROutPt;
            }
            #endregion

           
        }

        //内轮廓
        public static void DrawYGemstoneShapeInnerSide(Database db, Point2d stpointLM, ref Extents2d ext, double beamSegLength, double topWidth, double slope, double brslope, System.Data.DataRow dr, bool isLeft = true, string layerName = "H细线", double scale = 200)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight = double.Parse(dr["yshape_height"].ToString()) * 1000;
            double ySegLen = double.Parse(dr["yshape_segment_length"].ToString()) * 1000;
            int segNum = int.Parse(dr["yshape_segment_number"].ToString());
            string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();
            double bottomY = string.IsNullOrWhiteSpace(dr["bottom_y_width"].ToString()) ? 0 : double.Parse(dr["bottom_y_width"].ToString()) * 1000;

            String[] yHStr = yBHeightLayout.Split('+');
            double hy1 = 3 * 1000, hy2 = 2.6 * 1000;
            if (yHStr.Length > 0)
            {
                hy1 = Double.Parse(yHStr[0]) * 1000;
                if (yHStr.Length > 1)
                    hy2 = Double.Parse(yHStr[1]) * 1000;
            }

            #region Y形
            Point2d styPt1 = stpointLM.C2D(-topWidth * 0.5, beamSegLength * 4.5 * brslope);
            Point2d styPt2 = stpointLM.C2D(topWidth * 0.5, beamSegLength * 4.5 * brslope);
            //宝石底部宽度
            double btWidth = bottomY>0? topWidth+(bottomY- topWidth)*((yHeight - hy1 - hy2)/ yHeight) : Math.Round((topWidth + (yHeight-hy1-hy2 - cushionH) * slope * 2), 1);
            //Point3d stPt0 = Point3d.Origin.C3D(-beamSegLength * 0.5, beamSegLength * 4.5 * brslope, -topWidth * 0.5);
            //Point3d stPt1 = Point3d.Origin.C3D(-beamSegLength * 4.5, -yHeight+hy1+hy2, -btWidth * 0.5);
            if (!isLeft)
            {
                styPt1 = stpointLM.C2D(-topWidth * 0.5, -beamSegLength * 4.5 * brslope);
                styPt2 = stpointLM.C2D(topWidth * 0.5, -beamSegLength * 4.5 * brslope);
                //stPt0 = Point3d.Origin.C3D(-beamSegLength * 0.5, -beamSegLength * 4.5 * brslope, -topWidth * 0.5);
            }
            DimPloter.AddMultiMLeader(db, styPt1.C2D(topWidth * 0.5), styPt1.C2D(topWidth * 0.5).C2D(2 * scale, 10 * scale), styPt1.C2D(topWidth * 0.5).C2D(2 * scale, 10 * scale), "钢主梁构件", ref ext, scale);
            //double lenS = Math.Round(MathExtensions.PointDistance(stPt0, stPt1), 1);
            //double h = Math.Sqrt(Math.Pow(lenS, 2) - Math.Pow((btWidth - topWidth) * 0.5, 2));
            Point2d yPt1 = stpointLM.C2D(-btWidth * 0.5, -(yHeight - hy1 - hy2));
            Point2d yPt2 = stpointLM.C2D(btWidth * 0.5, -(yHeight - hy1 - hy2));

            //轮廓
            PLPloter.AddLine(db, styPt1.C2D(), yPt1, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), yPt2, ref ext, layerName);

            DimPloter.DimRot(db, styPt2.C3D(), yPt2.C3D(), yPt2.C3D(10 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            PLPloter.AddLine(db, styPt1.C2D(), styPt2, ref ext, layerName);
            PLPloter.AddLine(db, yPt1.C2D(), yPt2, ref ext, layerName);

            //DimPloter.DimAli(db, styPt1.C3D(), styPt2.C3D(), styPt2.C3D(0, 5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 0);

            DimPloter.DimAli(db, yPt1.C3D(), yPt2.C3D(), yPt2.C3D(0, -5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

            Point3d yLastPtL = yPt1.C3D();
            Point3d yLastPtR = yPt2.C3D();
            //Y悬臂
            for (int i = 0; i < segNum; i++)
            {
                Point3d yLOutPt = GeTools.CalPoint(yPt1.C3D(), styPt1.C3D(), (i + 1.000) / (segNum));
                Point3d yROutPt = GeTools.CalPoint(yPt2.C3D(), styPt2.C3D(), (i + 1.000) / (segNum));
                PLPloter.AddLine(db, yLOutPt.C2D(), yROutPt.C2D(), ref ext, layerName);
                if (isLeft)
                {
                    if (i % 2 != 0)
                    {
                        PLPloter.AddLine(db, yLOutPt.C2D(), yLastPtR.C2D(), ref ext, layerName);
                    }
                    else
                    {
                        PLPloter.AddLine(db, yROutPt.C2D(), yLastPtL.C2D(), ref ext, layerName);
                    }
                }
                else
                {
                    if (i % 2 != 0)
                    {
                        PLPloter.AddLine(db, yROutPt.C2D(), yLastPtL.C2D(), ref ext, layerName);
                    }
                    else
                    {
                        PLPloter.AddLine(db, yLOutPt.C2D(), yLastPtR.C2D(), ref ext, layerName);
                    }
                }
                DimPloter.DimAli(db, yLOutPt.C3D(), yROutPt.C3D(), yROutPt.C3D(0, 5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

                DimPloter.DimRot(db, yLastPtR.C3D(), yROutPt.C3D(), yPt2.C3D(5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                yLastPtL = yLOutPt;
                yLastPtR = yROutPt;
            }
            #endregion
            
        }
        #endregion

        #region Y墩
        public static void DrawGemstoneShape(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope,System.Data.DataRow dr,out double hh,out int lastIndex, int startIndex = 0, string layerName = "H细线", double scale = 200,bool isLM=false)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            double twobraceslope = 10;
            try
            {
                min = double.Parse(dr["gemstone_slope"].ToString());
                max = double.Parse(dr["gemstone_fifteen_slope"].ToString());
                twobraceslope = double.Parse(dr["gemstone_fifteen_brace_slope"].ToString());
            }
            catch { }
            double yHeight =string.IsNullOrWhiteSpace(dr["yshape_height"].ToString())? cushionH:double.Parse(dr["yshape_height"].ToString()) * 1000;

            double bottomY = string.IsNullOrWhiteSpace(dr["bottom_y_length"].ToString()) ? 0 : double.Parse(dr["bottom_y_length"].ToString()) * 100;
            double newL = bottomY <= 0 ? topWidth * 0.5 + (twHeight - cushionH) * slope : bottomY + (twHeight * 0.01 - yHeight * 0.01) * slope;

            bool one1Dim = false;
            string maninDB = "Φ" + dr["gemstone_main_diameter"].ToString() + "×" + dr["gemstone_main_thickness"].ToString();
            string braceDB = "Φ" + dr["gemstone_brace_diameter"].ToString() + "×" + dr["gemstone_brace_thickness"].ToString();
            string crossDB = "Φ" + dr["gemstone_cross_diameter"].ToString() + "×" + dr["gemstone_cross_thickness"].ToString();
            bool one2Dim = false;
            string maninDB1 = "Φ" + dr["gemstone_ten_main_diameter"].ToString() + "×"  + dr["gemstone_ten_main_thickness"].ToString();
            string braceDB1 = "Φ" + dr["gemstone_ten_brace_diameter"].ToString() + "×" + dr["gemstone_ten_brace_thickness"].ToString();
            string crossDB1 = "Φ" + dr["gemstone_ten_cross_diameter"].ToString() + "×" + dr["gemstone_ten_cross_thickness"].ToString();
            bool twoDim = false;
            string maninDB2 = "Φ" + dr["gemstone_fifteen_main_diameter"].ToString() + "×"  + dr["gemstone_fifteen_main_thickness"].ToString();
            string braceDB2 = "Φ" + dr["gemstone_fifteen_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_brace_thickness"].ToString();
            string braceDB2Add = "Φ" + dr["gemstone_fifteen_brace_diameter_add"].ToString() + "×" + dr["gemstone_fifteen_brace_thickness_add"].ToString();
            string crossDB2 = "Φ" + dr["gemstone_fifteen_cross_diameter"].ToString() + "×" + dr["gemstone_fifteen_cross_thickness"].ToString();
            string midDB2 = "Φ" + dr["gemstone_fifteen_middle_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_middle_brace_thickness"].ToString();
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
     

            double h = twHeight * 0.001 - yHeight * 0.001;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - htemp + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }
            lastIndex = segmentLst.Count - 1;
            #endregion

            #region 钢塔下部宝石结构


            double tw = topWidth;
            topWidth = topWidth + (yHeight - cushionH) * slope * 2;
          

            Point2d stPt = stpointLM.C2D(0, -yHeight);
            //Line lineL = PLPloter.AddLine(db, stPt.C2D(-topWidth * 0.5, 0), pt1, ref ext, layerName);
            //Line lineR = PLPloter.AddLine(db, stPt.C2D(topWidth * 0.5, 0), pt2, ref ext, layerName);
            Line lineL = new Line(stPt.C3D(-topWidth * 0.5, 0), pt1.C3D());
            Line lineR = new Line(stPt.C3D(topWidth * 0.5, 0), pt2.C3D());
            //PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            double ycurT = 0;
            double ycurB = 0;
            hh = yHeight;
            Point2d ptDim = stPt;
            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 1000;
                ycurT = ycurB - seg * 1000;
                double topW = topWidth + ycurT * slope * 2;
                if (i< startIndex)
                {
                    hh += seg * 1000;
                }
                if (i >= startIndex)
                {                   
                    if (i==startIndex)
                    {
                        ext = new Extents2d(stPt.C2D(-topWidth * 0.5, -ycurT), stPt.C2D(-topWidth * 0.5, -ycurT));
                        //ptDim = stPt.C2D(-(topWidth * 0.5+ ycurT * slope) , -ycurT);
                        ptDim = stPt.C2D(-(topWidth * 0.5 + (twHeight-yHeight+ cushionH) * slope), -ycurT);
                        if (isLM)
                            DimPloter.AddTop2BottomBJ(db, "E", stPt.C3D(topW * 0.5, -ycurT + 10.5 * scale), ref ext, scale,3, true);
                  
                    }
                    // 顶部端点
                    Line lineT = new Line(stPt.C3D(-topWidth * 0.5, -ycurT), stPt.C3D(topWidth * 0.5, -ycurT));
                    Line lineB = new Line(stPt.C3D(-topWidth * 0.5, -ycurB), stPt.C3D(topWidth * 0.5, -ycurB));

                    Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
                    Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);
                    Point3d ptLB = MathExtensions.GetIntersection(lineL, lineB);
                    Point3d ptRB = MathExtensions.GetIntersection(lineR, lineB);
                    double scaleTen = 1 / 2.000;

                    Point2d ptTMid = stPt.C2D(0, -ycurT);
                    Point2d ptBMid = stPt.C2D(0, -ycurB);
                    if (seg <= max)
                    {
                        PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);

                        if(seg <min)
                        {
                            if(!one1Dim)
                            {
                                double le = ptRB.X - ptLB.X;
                                Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), maninDB1, ref ext, scale);

                                p1 = ptBMid.C2D(le * 0.35);
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), crossDB1, ref ext, scale);

                                p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), braceDB1, ref ext, scale);
                                DimPloter.AddLRMark(db, "I", stPt.C3D(-topW * 0.5-5*scale, -ycurT - 4.5 * scale), ref ext, scale,true);
                                DimPloter.AddLRMark(db, "I", stPt.C3D(topW * 0.5 + 2 * scale, -ycurT - 4.5 * scale), ref ext, scale, true);
                            }
                            one1Dim = true;
                        }
                        else
                        {
                            if (!one2Dim)
                            {
                                double le = ptRB.X - ptLB.X;
                                Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), maninDB1, ref ext, scale);
                             
                                p1 = ptBMid.C2D(le * 0.35);      
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), crossDB1, ref ext, scale);

                                p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), braceDB1, ref ext, scale);
                                DimPloter.AddLRMark(db, "F", stPt.C3D(-topW * 0.5 - 5 * scale, -ycurT - 4.5 * scale), ref ext, scale, true);
                                DimPloter.AddLRMark(db, "F", stPt.C3D(topW * 0.5 + 2 * scale, -ycurT - 4.5 * scale), ref ext, scale, true);
                            }
                            one2Dim = true;
                        }
                    }
                    else
                    {
                        scaleTen = 1 / 2.000;
                        PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                        Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                        Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                        Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                        Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                        PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                        PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                        PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);

                        if (!twoDim)
                        {
                            double le = ptRB.X - ptLB.X;
                            Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), maninDB2, ref ext, scale);

                            p1 = ptBMid.C2D(le * 0.35);
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), crossDB2, ref ext, scale);

                            //p1 = GeTools.DivPoint( ptRB.C3D(), ptTMid.C3D(), 4).C2D();
                            //DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.25 + 2 * scale, 3 * scale), p1.C2D(le * 0.25 + 2 * scale, 3 * scale), braceDB2, ref ext, scale);

                            p1 = GeTools.DivPoint(ptMainMidR.C3D(), ptMidR.C3D()).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 2 * scale, 3 * scale), p1.C2D(le * 0.3 + 2 * scale, 3 * scale), midDB2, ref ext, scale);

                            DimPloter.AddLRMark(db, "G", stPt.C3D(-topW * 0.5 - 5 * scale, -ycurT- 4.5 * scale), ref ext, scale, true);
                            DimPloter.AddLRMark(db, "G", stPt.C3D(topW * 0.5 + 2 * scale, -ycurT - 4.5 * scale), ref ext, scale, true);

                            DimPloter.AddLRMark(db, "H", stPt.C3D(-topW * 0.5 - 5 * scale, -(ycurT+ycurB)*0.5 - 4.5 * scale), ref ext, scale, true);
                            DimPloter.AddLRMark(db, "H", stPt.C3D(topW * 0.5 + 2 * scale, -(ycurT + ycurB) * 0.5 - 4.5 * scale), ref ext, scale, true);
                            if(one2Dim|| one1Dim)
                            {
                                DimPloter.DimAli(db, stPt.C3D(topW * 0.5 + 2 * scale, -ycurT ), stPt.C3D(topW * 0.5 + 2 * scale, -ycurT +2000), stPt.C3D(topW * 0.5 + 5 * scale, -ycurT ), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
                                Point2d p = ptRT.C2D(-1000 * slope, 1000);
                                DimPloter.AddMultiMLeader(db, p, p.C2D(le * 0.1 + 3 * scale, 3 * scale), p.C2D(le * 0.1 + 3 * scale, 3 * scale), maninDB2, ref ext, scale);

                            }
                        }

                        if (seg <= twobraceslope)
                        {
                            double le = ptRB.X - ptLB.X;
                            Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptTMid.C3D(), 4).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.25 + 2 * scale, 3 * scale), p1.C2D(le * 0.25 + 2 * scale, 3 * scale), braceDB2, ref ext, scale);
                        }
                        else
                        {
                            double le = ptRB.X - ptLB.X;
                            Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptTMid.C3D(), 4).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.25 + 2 * scale, 3 * scale), p1.C2D(le * 0.25 + 2 * scale, 3 * scale), braceDB2Add, ref ext, scale);
                        }
                        twoDim = true;
                       
                    }
                    PLPloter.AddLine(db, ptLB.C2D(), ptLT.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptRT.C2D(), ref ext, layerName);
                    if (i == segmentLst.Count - 1)
                    {
                        PLPloter.AddLine(db, ptRB.C2D(), ptLB.C2D(), ref ext, layerName);
                        DimPloter.DimAli(db, ptLB.C3D(), ptBMid.C3D(), ptBMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                        DimPloter.DimAli(db, ptRB.C3D(), ptBMid.C3D(), ptBMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                    }
                    DimPloter.DimAli(db, ptLT.C3D(), ptTMid.C3D(), ptTMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                    DimPloter.DimAli(db, ptRT.C3D(), ptTMid.C3D(), ptTMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
            
                    DimPloter.DimRot(db, ptRT.C3D(), ptRB.C3D(), ptDim.C3D(-10 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter);

                }
            }
            if(isLM)
            DimPloter.AddTop2BottomBJ(db, "E", stPt.C3D(topWidth * 0.5  + ycurB * slope, -ycurB - 4.5 * scale), ref ext, scale, 3, false);
            #endregion

            string pierNo = dr["name"].ToString();
            if (pierNo == "P1" && isLM)
            {
                Point2d styPt1 = stpointLM.C2D(-tw * 4.5, tw * 4.5 * brslope  );
                Point2d styPt2 = stpointLM.C2D(tw * 4.5, -tw * 4.5 * brslope );
                Point2d yPt1 = stpointLM.C2D(-topWidth * 0.5,- yHeight);
                Point2d yPt2 = stpointLM.C2D(topWidth * 0.5, -yHeight);
                string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();
                String[] yHStr = yBHeightLayout.Split('+');
                double hy1 = 3 * 1000, hy2 = 2.6 * 1000;
                if (yHStr.Length > 0)
                {
                    hy1 = Double.Parse(yHStr[0]) * 1000;
                    if (yHStr.Length > 1)
                        hy2 = Double.Parse(yHStr[1]) * 1000;
                }
                Point2d ybtMidPt = stpointLM.C2D(0, -yHeight+hy1 + hy2);

                Point3d yLastPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), 15);
                Point3d yLastPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), 15);

                Point3d yp1 = GeTools.DivPoint(yPt1.C3D(), ybtMidPt.C3D(),4);
                Point3d yp2 = GeTools.DivPoint(yPt2.C3D(), ybtMidPt.C3D(),4);
                PLPloter.AddLine(db, yPt1.C2D(), yLastPtL.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yPt2.C2D(), yLastPtR.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yPt1.C2D(), yp1.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yPt2.C2D(), yp2.C2D(), ref ext, layerName);
            }
        }

        public static void DrawGemstoneSectionShape(Database db, Point2d stpointLM, ref Extents2d extS, double twHeight, double topWidth, double slope, double topLength, double slopeL, double brslope, System.Data.DataRow dr,out double hS, int startIndex = 0, string layerName = "H细线", double scale = 200)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight = string.IsNullOrWhiteSpace(dr["yshape_height"].ToString()) ? cushionH : double.Parse(dr["yshape_height"].ToString()) * 1000;
            bool one1Dim = false;
            string maninDB = "Φ" + dr["gemstone_main_diameter"].ToString() + "×" + dr["gemstone_main_thickness"].ToString();
            string braceDB = "Φ" + dr["gemstone_brace_diameter"].ToString() + "×" + dr["gemstone_brace_thickness"].ToString();
            string crossDB = "Φ" + dr["gemstone_cross_diameter"].ToString() + "×" + dr["gemstone_cross_thickness"].ToString();
            string flatDB = "Φ" + dr["gemstone_flat_brace_diameter"].ToString() + "×" + dr["gemstone_flat_brace_thickness"].ToString();
            bool one2Dim = false;
            string maninDB1 = "Φ" + dr["gemstone_ten_main_diameter"].ToString() + "×" + dr["gemstone_ten_main_thickness"].ToString();
            string braceDB1 = "Φ" + dr["gemstone_ten_brace_diameter"].ToString() + "×" + dr["gemstone_ten_brace_thickness"].ToString();
            string crossDB1 = "Φ" + dr["gemstone_ten_cross_diameter"].ToString() + "×" + dr["gemstone_ten_cross_thickness"].ToString();
            string flatDB1 = "Φ" + dr["gemstone_ten_flat_brace_diameter"].ToString() + "×" + dr["gemstone_ten_flat_brace_thickness"].ToString();
            bool twoDim = false;
            string maninDB2 = "Φ" + dr["gemstone_fifteen_main_diameter"].ToString() + "×" + dr["gemstone_fifteen_main_thickness"].ToString();
            string braceDB2 = "Φ" + dr["gemstone_fifteen_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_brace_thickness"].ToString();
            string crossDB2 = "Φ" + dr["gemstone_fifteen_cross_diameter"].ToString() + "×" + dr["gemstone_fifteen_cross_thickness"].ToString();
            string midDB2 = "Φ" + dr["gemstone_fifteen_middle_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_middle_brace_thickness"].ToString();
            string flatDB2 = "Φ" + dr["gemstone_fifteen_flat_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_flat_brace_thickness"].ToString();
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            Extents2d ext = extS;
           
            double h = twHeight * 0.001 - yHeight * 0.001;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - htemp + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }

            #endregion

            topWidth = topWidth + (yHeight - cushionH) * slope * 2;
            topLength = topLength + (yHeight - cushionH) * slopeL * 2;
            double ycurT = 0;
            double ycurB = 0;
            double hh = yHeight;
            Point2d stPt = stpointLM.C2D(0, -yHeight);
          
            bool isDraw = false;
            Point2d pt = stPt.C2D(0, -10*scale);
            Extents2d extSextion = new Extents2d(pt, pt);
            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 1000;
                ycurT = ycurB - seg * 1000;
                double topW = topWidth + ycurT * slope * 2;
               
                double topL = topLength + ycurT * slopeL * 2;
                double topMidW = topWidth + (ycurT + ycurB) * 0.5 * slope * 2;
                double topMidL = topLength + (ycurT + ycurB) * 0.5 * slopeL * 2;
                double bW = topWidth + ycurB * slope * 2;
                double bL = topWidth + ycurB * slopeL * 2;
                if (i < startIndex)
                {
                    hh += seg * 1000;
                }
                Point2d ptStart = stPt.C2D(0, -ycurT);
                if (i >= startIndex)
                {
                    if (!isDraw)
                    {
                        pt = ptStart;
                        extSextion = new Extents2d(pt, pt);
                    }
                    if (seg <= max)
                    {
                        if (seg < min)
                        {
                            if (!one1Dim)
                            {
                                if (!isDraw)
                                {
                                    ext = new Extents2d(pt, pt);
                                    extSextion = new Extents2d(pt, pt);
                                }

                                    PLPloter.AddPloy4(db, pt, topW * 0.5, topW * 0.5, topL, ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                                Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topL), pt.C3D(-topW * 0.5, -topL * 0.5)).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(2 * scale, 3 * scale), p1.C2D(2 * scale, 3 * scale), flatDB, ref ext, scale);

                                TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "I-I", "", scale);
                                isDraw = true;

                                extSextion = extSextion.Add(ext);
                            }
                            one1Dim = true;
                        }
                        else
                        {
                            if (!one2Dim)
                            {
                                if (!isDraw)
                                {
                                    ext = new Extents2d(pt, pt);
                                    extSextion = new Extents2d(pt, pt);
                                }
                                pt = pt.C2D(0, -ext.L() - 5 * scale);
                                ext = new Extents2d(pt.C2D(), pt.C2D());
                                PLPloter.AddPloy4(db, pt, topW * 0.5, topW * 0.5, topL, ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                                Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topL), pt.C3D(-topW * 0.5, -topL * 0.5)).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(2 * scale, 3 * scale), p1.C2D(2 * scale, 3 * scale), flatDB1, ref ext, scale);
                                TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "F-F", "", scale);
                                isDraw = true;

                                extSextion = extSextion.Add(ext);
                            }
                            one2Dim = true;
                        }
                    }
                    else
                    {
                        if (!twoDim)
                        {
                            if (!isDraw)
                            {
                                ext = new Extents2d(pt, pt);
                                extSextion = new Extents2d(pt, pt);
                            }
                            //if (one1Dim || one2Dim)
                            //    pt = stPt.C2D(0, -ycurT + seg * 1000 * 0.8);
                            //else
                            //    pt = stPt.C2D(0, -ycurT + seg * 1000 * 0.1);
                            pt = pt.C2D(0, -ext.L() - 5 * scale);
                            ext = new Extents2d(pt.C2D(), pt.C2D());

                            PLPloter.AddPloy4(db, pt, topW * 0.5, topW * 0.5, topL, ref ext, "H细线");
                            PLPloter.AddLine(db, pt, pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                            Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topL), pt.C3D(-topW * 0.5, -topL * 0.5)).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(2 * scale, 3 * scale), p1.C2D(2 * scale, 3 * scale), flatDB2, ref ext, scale);
                            TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "G-G", "", scale);
                            extSextion = extSextion.Add(ext);

                            pt = pt.C2D(0, -ext.L() - 5 * scale);
                            ext = new Extents2d(pt.C2D(), pt.C2D());
                            //if (one1Dim || one2Dim)
                            //    pt = stPt.C2D(0, -ycurB + seg * 1000 * 0.1);
                            //else
                            //    pt = stPt.C2D(0, -ycurB - seg * 1000 * 0.6);
                            PLPloter.AddPloy4(db, pt, topMidW * 0.5, topMidW * 0.5, topMidL, ref ext, "H细线");
                            PLPloter.AddLine(db, pt.C2D(-topMidW * 0.5, -topMidL * 0.25), pt.C2D(-topMidW * 0.25, 0), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(topMidW * 0.5, -topMidL * 0.25), pt.C2D(topMidW * 0.25, 0), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(-topMidW * 0.5, -topMidL * 0.75), pt.C2D(-topMidW * 0.25, -topMidL), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(topMidW * 0.5, -topMidL * 0.75), pt.C2D(topMidW * 0.25, -topMidL), ref ext, layerName);
                            Point2d p2 = GeTools.MidPoint(pt.C3D(-topMidW * 0.5, -topMidL * 0.75), pt.C3D(-topMidW * 0.25, -topMidL)).C2D();
                            DimPloter.AddMultiMLeader(db, p2.C2D(), p2.C2D(2 * scale, 3 * scale), p2.C2D(2 * scale, 3 * scale), midDB2, ref ext, scale);
                            TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "H-H", "", scale);
                            isDraw = true;
                            extSextion = extSextion.Add(ext);
                        }
                        twoDim = true;
                    }
                }
            }

         
            extS = extS.Add(extSextion);
            hS = extSextion.L();
        }
        #endregion

        #region T墩
        public static void DrawGemstoneShape(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope, System.Data.DataRow dr,  string layerName = "H细线", double scale = 200, bool isLM = false)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight = string.IsNullOrWhiteSpace(dr["yshape_height"].ToString()) ? cushionH : double.Parse(dr["yshape_height"].ToString()) * 1000;

            double bottomY = string.IsNullOrWhiteSpace(dr["bottom_y_length"].ToString()) ? 0 : double.Parse(dr["bottom_y_length"].ToString()) * 100;
            double newL = bottomY <= 0 ? topWidth * 0.5 + (twHeight - cushionH) * slope : bottomY + (twHeight * 0.01 - yHeight * 0.01) * slope;

            bool one1Dim = false;
            string maninDB = "Φ" + dr["gemstone_main_diameter"].ToString() + "×" + dr["gemstone_main_thickness"].ToString();
            string braceDB = "Φ" + dr["gemstone_brace_diameter"].ToString() + "×" + dr["gemstone_brace_thickness"].ToString();
            string crossDB = "Φ" + dr["gemstone_cross_diameter"].ToString() + "×" + dr["gemstone_cross_thickness"].ToString();
            bool one2Dim = false;
            string maninDB1 = "Φ" + dr["gemstone_ten_main_diameter"].ToString() + "×" + dr["gemstone_ten_main_thickness"].ToString();
            string braceDB1 = "Φ" + dr["gemstone_ten_brace_diameter"].ToString() + "×" + dr["gemstone_ten_brace_thickness"].ToString();
            string crossDB1 = "Φ" + dr["gemstone_ten_cross_diameter"].ToString() + "×" + dr["gemstone_ten_cross_thickness"].ToString();
            bool twoDim = false;
            string maninDB2 = "Φ" + dr["gemstone_fifteen_main_diameter"].ToString() + "×" + dr["gemstone_fifteen_main_thickness"].ToString();
            string braceDB2 = "Φ" + dr["gemstone_fifteen_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_brace_thickness"].ToString();
            string crossDB2 = "Φ" + dr["gemstone_fifteen_cross_diameter"].ToString() + "×" + dr["gemstone_fifteen_cross_thickness"].ToString();
            string midDB2 = "Φ" + dr["gemstone_fifteen_middle_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_middle_brace_thickness"].ToString();
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);


            double h = twHeight * 0.001 - yHeight * 0.001;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - htemp + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }
          
            #endregion

            #region 钢塔下部宝石结构


            double tw = topWidth;
            topWidth = topWidth + (yHeight - cushionH) * slope * 2;


            Point2d stPt = stpointLM.C2D(0, -yHeight);
            Point2d stPt1 = stpointLM.C2D(0, -yHeight);
            //Line lineL = PLPloter.AddLine(db, stPt.C2D(-topWidth * 0.5, 0), pt1, ref ext, layerName);
            //Line lineR = PLPloter.AddLine(db, stPt.C2D(topWidth * 0.5, 0), pt2, ref ext, layerName);
            Line lineL = new Line(stPt.C3D(-topWidth * 0.5, 0), pt1.C3D());
            Line lineR = new Line(stPt.C3D(topWidth * 0.5, 0), pt2.C3D());
          
            //PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            double ycurT = 0;
            double ycurB = 0;
            Point2d ptDim = stPt;
            double topW1 = topWidth + ycurT * slope * 2;
            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 1000;
                ycurT = ycurB - seg * 1000;
                double topW = topWidth + ycurT * slope * 2;


                if (i == 0)
                {
                    ext = new Extents2d(stPt.C2D(-topWidth * 0.5, -ycurT), stPt.C2D(-topWidth * 0.5, -ycurT));
                    ptDim = stPt.C2D(-(topWidth * 0.5 + (twHeight - cushionH) * slope), -ycurT);
                    if (isLM)
                        DimPloter.AddTop2BottomBJ(db, "A", stPt.C3D(topW * 0.5, -ycurT  +5.5*scale+4.5 * scale), ref ext, scale, 3, true);
                }

                // 顶部端点
                Line lineT = new Line(stPt.C3D(-topWidth * 0.5, -ycurT), stPt.C3D(topWidth * 0.5, -ycurT));
                Line lineB = new Line(stPt.C3D(-topWidth * 0.5, -ycurB), stPt.C3D(topWidth * 0.5, -ycurB));

                Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
                Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);
                Point3d ptLB = MathExtensions.GetIntersection(lineL, lineB);
                Point3d ptRB = MathExtensions.GetIntersection(lineR, lineB);
                double scaleTen = 1 / 2.000;

                Point2d ptTMid = stPt.C2D(0, -ycurT);
                Point2d ptBMid = stPt.C2D(0, -ycurB);
                if (seg <= max)
                {
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);

                    if (seg < min)
                    {
                        if (!one1Dim)
                        {
                            double le = ptRB.X - ptLB.X;
                            Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), maninDB1, ref ext, scale);

                            p1 = ptBMid.C2D(le * 0.35);
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), crossDB1, ref ext, scale);

                            p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), braceDB1, ref ext, scale);
                            DimPloter.AddLRMark(db, "B", stPt1.C3D(-topW1 * 0.5 - (twHeight - cushionH) * slope - 5 * scale, -ycurT - 4.5 * scale), ref ext, scale, true);
                            DimPloter.AddLRMark(db, "B", stPt1.C3D(topW1 * 0.5 + 2 * scale+ (twHeight - cushionH) * slope, -ycurT - 4.5 * scale), ref ext, scale, true);
                        }
                        one1Dim = true;
                    }
                    else
                    {
                        if (!one2Dim)
                        {
                            double le = ptRB.X - ptLB.X;
                            Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), maninDB1, ref ext, scale);

                            p1 = ptBMid.C2D(le * 0.35);
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), crossDB1, ref ext, scale);

                            p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), braceDB1, ref ext, scale);
                            DimPloter.AddLRMark(db, "C", stPt1.C3D(-topW1 * 0.5 - 5 * scale - (twHeight - cushionH) * slope, -ycurT - 4.5 * scale), ref ext, scale, true);
                            DimPloter.AddLRMark(db, "C", stPt1.C3D(topW1 * 0.5 + 2 * scale + (twHeight - cushionH) * slope, -ycurT - 4.5 * scale), ref ext, scale, true);
                        }
                        one2Dim = true;
                    }
                }
                else
                {
                    scaleTen = 1 / 2.000;
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                    Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                    Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                    Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                    Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                    PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);

                    if (!twoDim)
                    {
                        double le = ptRB.X - ptLB.X;
                        Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                        DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), p1.C2D(le * 0.1 + 1 * scale, 3 * scale), maninDB2, ref ext, scale);

                        p1 = ptBMid.C2D(le * 0.35);
                        DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), p1.C2D(le * 0.3 + 1 * scale, 4 * scale), crossDB2, ref ext, scale);

                        p1 = GeTools.DivPoint(ptRB.C3D(), ptTMid.C3D(), 4).C2D();
                        DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), p1.C2D(le * 0.5 + 2 * scale, 3 * scale), braceDB2, ref ext, scale);

                        p1 = GeTools.DivPoint(ptMainMidR.C3D(), ptMidR.C3D()).C2D();
                        DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(le * 0.3 + 2 * scale, 3 * scale), p1.C2D(le * 0.3 + 2 * scale, 3 * scale), midDB2, ref ext, scale);

                        DimPloter.AddLRMark(db, "D", stPt1.C3D(-topW1 * 0.5 - 5 * scale - (twHeight - cushionH) * slope, -ycurT - 4.5 * scale), ref ext, scale, true);
                        DimPloter.AddLRMark(db, "D", stPt1.C3D(topW1 * 0.5 + 2 * scale + (twHeight - cushionH) * slope, -ycurT - 4.5 * scale), ref ext, scale, true);

                        DimPloter.AddLRMark(db, "E", stPt1.C3D(-topW1 * 0.5 - 5 * scale - (twHeight - cushionH) * slope, -(ycurT + ycurB) * 0.5 - 4.5 * scale), ref ext, scale, true);
                        DimPloter.AddLRMark(db, "E", stPt1.C3D(topW1 * 0.5 + 2 * scale + (twHeight - cushionH) * slope, -(ycurT + ycurB) * 0.5 - 4.5 * scale), ref ext, scale, true);
                        if (one2Dim || one1Dim)
                        {
                            DimPloter.DimAli(db, stPt.C3D(topW * 0.5 + 2 * scale, -ycurT), stPt.C3D(topW * 0.5 + 2 * scale, -ycurT + 2000), stPt.C3D(topW * 0.5 + 5 * scale, -ycurT), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
                            Point2d p = ptRT.C2D(-1000 * slope, 1000);
                            DimPloter.AddMultiMLeader(db, p, p.C2D(le * 0.1 + 3 * scale, 3 * scale), p.C2D(le * 0.1 + 3 * scale, 3 * scale), maninDB2, ref ext, scale);

                        }
                    }
                    twoDim = true;
                }
                PLPloter.AddLine(db, ptLB.C2D(), ptLT.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, ptRB.C2D(), ptRT.C2D(), ref ext, layerName);
                if (i == segmentLst.Count - 1)
                {
                    PLPloter.AddLine(db, ptRB.C2D(), ptLB.C2D(), ref ext, layerName);
                    DimPloter.DimAli(db, ptLB.C3D(), ptBMid.C3D(), ptBMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                    DimPloter.DimAli(db, ptRB.C3D(), ptBMid.C3D(), ptBMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                }
                DimPloter.DimAli(db, ptLT.C3D(), ptTMid.C3D(), ptTMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                DimPloter.DimAli(db, ptRT.C3D(), ptTMid.C3D(), ptTMid.C3D(0, 3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

                DimPloter.DimRot(db, ptRT.C3D(), ptRB.C3D(), ptDim.C3D(-20 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Millimeter);


            }
            if (isLM)
                DimPloter.AddTop2BottomBJ(db, "A", stPt.C3D(topWidth * 0.5 + ycurB * slope, -ycurB - 4.5 * scale), ref ext, scale, 3, false);
            #endregion

            //string pierNo = dr["name"].ToString();
            //if (pierNo == "P1" && isLM)
            //{
            //    Point2d styPt1 = stpointLM.C2D(-tw * 4.5, tw * 4.5 * brslope);
            //    Point2d styPt2 = stpointLM.C2D(tw * 4.5, -tw * 4.5 * brslope);
            //    Point2d yPt1 = stpointLM.C2D(-topWidth * 0.5, -yHeight);
            //    Point2d yPt2 = stpointLM.C2D(topWidth * 0.5, -yHeight);
            //    string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();
            //    String[] yHStr = yBHeightLayout.Split('+');
            //    double hy1 = 3 * 1000, hy2 = 2.6 * 1000;
            //    if(yBHeightLayout.c)
            //    if (yHStr.Length > 0)
            //    {
            //        hy1 = Double.Parse(yHStr[0]) * 1000;
            //        if (yHStr.Length > 1)
            //            hy2 = Double.Parse(yHStr[1]) * 1000;
            //    }
            //    Point2d ybtMidPt = stpointLM.C2D(0, -yHeight + hy1 + hy2);

            //    Point3d yLastPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), 15);
            //    Point3d yLastPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), 15);

            //    Point3d yp1 = GeTools.DivPoint(yPt1.C3D(), ybtMidPt.C3D(), 4);
            //    Point3d yp2 = GeTools.DivPoint(yPt2.C3D(), ybtMidPt.C3D(), 4);
            //    PLPloter.AddLine(db, yPt1.C2D(), yLastPtL.C2D(), ref ext, layerName);
            //    PLPloter.AddLine(db, yPt2.C2D(), yLastPtR.C2D(), ref ext, layerName);
            //    PLPloter.AddLine(db, yPt1.C2D(), yp1.C2D(), ref ext, layerName);
            //    PLPloter.AddLine(db, yPt2.C2D(), yp2.C2D(), ref ext, layerName);
            //}
        }
        public static void DrawGemstoneShapeRotate(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope, System.Data.DataRow dr, string layerName = "H细线", double scale = 200, bool isLM = false)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            double minH = twHeight, maxH = twHeight;
            string segType = "0";
            string is_add_gemstone_fifteen = "0";
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
          
            segType = dr["gemstone_segment_type"].ToString();
            is_add_gemstone_fifteen = dr["is_add_gemstone_fifteen"].ToString();
            double yHeight = string.IsNullOrWhiteSpace(dr["yshape_height"].ToString()) ? cushionH : double.Parse(dr["yshape_height"].ToString()) * 1000;
            try
            {
                minH = double.Parse(dr["gemstone_height"].ToString()) * 1000- yHeight;
                maxH = double.Parse(dr["gemstone_fifteen_height"].ToString()) * 1000- yHeight;
            }
            catch { }
            double bottomY = string.IsNullOrWhiteSpace(dr["bottom_y_length"].ToString()) ? 0 : double.Parse(dr["bottom_y_length"].ToString()) * 100;
            double newL = bottomY <= 0 ? topWidth * 0.5 + (twHeight - cushionH) * slope : bottomY + (twHeight * 0.01 - yHeight * 0.01) * slope;

            bool one1Dim = false;
            string maninDB = "Φ" + dr["gemstone_main_diameter"].ToString() + "×" + dr["gemstone_main_thickness"].ToString();
            string braceDB = "Φ" + dr["gemstone_brace_diameter"].ToString() + "×" + dr["gemstone_brace_thickness"].ToString();
            string crossDB = "Φ" + dr["gemstone_cross_diameter"].ToString() + "×" + dr["gemstone_cross_thickness"].ToString();
            bool one2Dim = false;
            string maninDB1 = "Φ" + dr["gemstone_ten_main_diameter"].ToString() + "×" + dr["gemstone_ten_main_thickness"].ToString();
            string braceDB1 = "Φ" + dr["gemstone_ten_brace_diameter"].ToString() + "×" + dr["gemstone_ten_brace_thickness"].ToString();
            string crossDB1 = "Φ" + dr["gemstone_ten_cross_diameter"].ToString() + "×" + dr["gemstone_ten_cross_thickness"].ToString();
            bool twoDim = false;
            string maninDB2 = "Φ" + dr["gemstone_fifteen_main_diameter"].ToString() + "×" + dr["gemstone_fifteen_main_thickness"].ToString();
            string braceDB2 = "Φ" + dr["gemstone_fifteen_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_brace_thickness"].ToString();
            string crossDB2 = "Φ" + dr["gemstone_fifteen_cross_diameter"].ToString() + "×" + dr["gemstone_fifteen_cross_thickness"].ToString();
            string midDB2 = "Φ" + dr["gemstone_fifteen_middle_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_middle_brace_thickness"].ToString();
            Point2d pt1 = stpointLM.C2D(twHeight,- topWidth * 0.5 - (twHeight - cushionH) * slope );
            Point2d pt2 = stpointLM.C2D(twHeight, topWidth * 0.5 + (twHeight - cushionH) * slope);


            double h = twHeight * 0.001 - yHeight * 0.001;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                if (seg > segmentList[segmentList.Count - 1] * 0.5)
                                {
                                    seg = h - (htemp - segmentList[i]);
                                    segmentLst.Add(seg);
                                }
                                else
                                {
                                    seg = h - (htemp - segmentList[i]);
                                    seg = seg + segmentList[i];
                                    segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                    segmentLst.Add(seg);
                                }
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - htemp + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }

            #endregion

            #region 钢塔下部宝石结构


            double tw = topWidth;
            topWidth = topWidth + (yHeight - cushionH) * slope * 2;


            Point2d stPt = stpointLM.C2D(yHeight);
            Point2d stPt1 = stpointLM.C2D(yHeight);
            //Line lineL = PLPloter.AddLine(db, stPt.C2D(-topWidth * 0.5, 0), pt1, ref ext, layerName);
            //Line lineR = PLPloter.AddLine(db, stPt.C2D(topWidth * 0.5, 0), pt2, ref ext, layerName);
            Line lineL = new Line(stPt.C3D(0,-topWidth * 0.5), pt1.C3D());
            Line lineR = new Line(stPt.C3D(0,topWidth * 0.5), pt2.C3D());
            double ww = (twHeight - cushionH) * slope;
            //PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            double ycurT = 0;
            double ycurB = 0;
            Point2d ptDim = stPt;
            double topW1 = topWidth + ycurT * slope * 2;
            double topW10 = topWidth + ycurT * slope * 2;
            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 1000;
                ycurT = ycurB - seg * 1000;
                double topW = topWidth + ycurT * slope * 2;


                if (i == 0)
                {
                    ext = new Extents2d(stPt.C2D( ycurT, -topWidth * 0.5), stPt.C2D( ycurT, -topWidth * 0.5));
                    ptDim = stPt.C2D( ycurT, -(topWidth * 0.5 + (twHeight - cushionH) * slope) - 10 * scale);
                    if (isLM)
                        DimPloter.AddLeft2RightBJ(db, "A", stPt.C3D(ycurT - 2.5 * scale - 4.5 * scale, topWidth * 0.5 + (twHeight - cushionH) * slope), ref ext, scale, 3, true);
                }

                // 顶部端点
                Line lineT = new Line(stPt.C3D( ycurT, -topWidth * 0.5), stPt.C3D(ycurT, topWidth * 0.5));
                Line lineB = new Line(stPt.C3D( ycurB, -topWidth * 0.5), stPt.C3D( ycurB, topWidth * 0.5));

                Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
                Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);
                Point3d ptLB = MathExtensions.GetIntersection(lineL, lineB);
                Point3d ptRB = MathExtensions.GetIntersection(lineR, lineB);
                double scaleTen = 1 / 2.000;

                Point2d ptTMid = stPt.C2D(ycurT);
                Point2d ptBMid = stPt.C2D(ycurB);
                if (segType == "0")
                {
                    #region 根据节段划分
                    if (seg <= max)
                    {
                        PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);

                        if (seg < min)
                        {
                            if (!one1Dim)
                            {
                                double le = ptRB.Y - ptLB.Y;
                                Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.1 + 8 * scale), p1.C2D(3 * scale, le * 0.1 + 8 * scale), maninDB, ref ext, scale);

                                p1 = ptBMid.C2D(0, -le * 0.35);
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), crossDB, ref ext, scale);
                                topW1 = ptRT.Y - ptLT.Y;
                                p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.5 + 0 * scale), p1.C2D(3 * scale, le * 0.5 + 0 * scale), braceDB, ref ext, scale);
                                DimPloter.AddLRMarkRotate(db, "B", stPt1.C3D(ycurT + 4.5 * scale, -topW1 * 0.5 - 8.5 * scale), ref ext, scale, true);
                                DimPloter.AddLRMarkRotate(db, "B", stPt1.C3D(ycurT + 4.5 * scale, topW1 * 0.5 + 3.5 * scale), ref ext, scale, true);
                            }
                            one1Dim = true;
                        }
                        else
                        {
                            if (!one2Dim)
                            {
                                double le = ptRB.Y - ptLB.Y;
                                Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.1 + 8 * scale), p1.C2D(3 * scale, le * 0.1 + 8 * scale), maninDB1, ref ext, scale);

                                p1 = ptBMid.C2D(0, -le * 0.35);
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), crossDB1, ref ext, scale);
                                topW1 = ptRT.Y - ptLT.Y;
                                p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.5 - 1 * scale), p1.C2D(3 * scale, le * 0.5 - 1 * scale), braceDB1, ref ext, scale);
                                DimPloter.AddLRMarkRotate(db, "C", stPt1.C3D(ycurT + 4.5 * scale, -topW1 * 0.5 - 8.5 * scale), ref ext, scale, true);
                                DimPloter.AddLRMarkRotate(db, "C", stPt1.C3D(ycurT + 4.5 * scale, topW1 * 0.5 + 3.5 * scale), ref ext, scale, true);
                            }
                            one2Dim = true;
                        }
                    }
                    else
                    {
                        scaleTen = 1 / 2.000;
                        PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                        Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                        Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                        Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                        Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                        PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                        PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                        PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);

                        if (!twoDim)
                        {
                            double le = ptRB.Y - ptLB.Y;
                            Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.1 + 8 * scale), p1.C2D(3 * scale, le * 0.1 + 8 * scale), maninDB2, ref ext, scale);

                            p1 = ptBMid.C2D(0, -le * 0.35);
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(4 * scale, -le * 0.3 - 2 * scale), p1.C2D(4 * scale, -le * 0.3 - 2 * scale), crossDB2, ref ext, scale);

                            p1 = GeTools.DivPoint(ptRB.C3D(), ptTMid.C3D(), 4).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.2 - 1 * scale), p1.C2D(3 * scale, le * 0.2 - 1 * scale), braceDB2, ref ext, scale);

                            p1 = GeTools.DivPoint(ptMainMidR.C3D(), ptMidR.C3D()).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, -le * 0.2), p1.C2D(3 * scale, -le * 0.2), midDB2, ref ext, scale);
                            topW1 = topW10;
                            DimPloter.AddLRMarkRotate(db, "D", stPt1.C3D(ycurT + 4.5 * scale, -topW1 * 0.5 - 7 * scale - (twHeight - cushionH) * slope), ref ext, scale, true);
                            DimPloter.AddLRMarkRotate(db, "D", stPt1.C3D(ycurT + 4.5 * scale, topW1 * 0.5 + 4 * scale + (twHeight - cushionH) * slope), ref ext, scale, true);

                            DimPloter.AddLRMarkRotate(db, "E", stPt1.C3D((ycurT + ycurB) * 0.5 + 4.5 * scale, -topW1 * 0.5 - 6 * scale - (twHeight - cushionH) * slope), ref ext, scale, true);
                            DimPloter.AddLRMarkRotate(db, "E", stPt1.C3D((ycurT + ycurB) * 0.5 + 4.5 * scale, topW1 * 0.5 + 4 * scale + (twHeight - cushionH) * slope), ref ext, scale, true);
                            if (one2Dim || one1Dim)
                            {
                                DimPloter.DimAli(db, stPt.C3D(ycurT, topW * 0.5 + 2 * scale), stPt.C3D(ycurT - 2000, topW * 0.5 + 2 * scale), stPt.C3D(ycurT, topW * 0.5 + 5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
                                Point2d p = ptLT.C2D(-1000, 1000 * slope);
                                DimPloter.AddMultiMLeader(db, p, p.C2D(3 * scale, -le * 0.1 - 1 * scale), p.C2D(3 * scale, -le * 0.1 - 1 * scale), maninDB2, ref ext, scale);

                            }
                        }
                        twoDim = true;
                    }
                    PLPloter.AddLine(db, ptLB.C2D(), ptLT.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptRT.C2D(), ref ext, layerName);
                    if (i == segmentLst.Count - 1)
                    {
                        PLPloter.AddLine(db, ptRB.C2D(), ptLB.C2D(), ref ext, layerName);
                        DimPloter.DimAli(db, ptLB.C3D(), ptBMid.C3D(), ptBMid.C3D(3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                        DimPloter.DimAli(db, ptRB.C3D(), ptBMid.C3D(), ptBMid.C3D(3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                    }
                    DimPloter.DimAli(db, ptLT.C3D(), ptTMid.C3D(), ptTMid.C3D(-3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                    DimPloter.DimAli(db, ptRT.C3D(), ptTMid.C3D(), ptTMid.C3D(-3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

                    DimPloter.DimRot(db, ptRT.C3D(), ptRB.C3D(), ptDim.C3D(-20 * scale), ref ext, 0, scale, "", Unit.Millimeter, Unit.Millimeter);

                    #endregion
                }
                else
                {
                    if (ycurB <= maxH)
                    {
                        PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);

                        if (ycurB <= minH)
                        {
                            if (!one1Dim)
                            {
                                double le = ptRB.Y - ptLB.Y;
                                Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.1 + 8 * scale), p1.C2D(3 * scale, le * 0.1 + 8 * scale), maninDB, ref ext, scale);

                                p1 = ptBMid.C2D(0, -le * 0.35);
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), crossDB, ref ext, scale);
                                topW1 = ptRT.Y - ptLT.Y;
                                p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.5 + 0 * scale), p1.C2D(3 * scale, le * 0.5 + 0 * scale), braceDB, ref ext, scale);
                                DimPloter.AddLRMarkRotate(db, "B", stPt1.C3D(ycurT + 4.5 * scale, -topW1 * 0.5 - 8.5 * scale), ref ext, scale, true);
                                DimPloter.AddLRMarkRotate(db, "B", stPt1.C3D(ycurT + 4.5 * scale, topW1 * 0.5 + 3.5 * scale), ref ext, scale, true);
                            }
                            one1Dim = true;
                        }
                        else
                        {
                            if (!one2Dim)
                            {
                                double le = ptRB.Y - ptLB.Y;
                                Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.5 + 1 * scale), p1.C2D(3 * scale, le * 0.5 + 1 * scale), maninDB1, ref ext, scale);

                                p1 = ptBMid.C2D(0, -le * 0.35);
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), p1.C2D(4 * scale, -le * 0.3 - 3 * scale), crossDB1, ref ext, scale);
                                topW1 = ptRT.Y - ptLT.Y;
                                p1 = GeTools.MidPoint(ptTMid.C3D(), ptRB.C3D()).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.5 - 1 * scale), p1.C2D(3 * scale, le * 0.5 - 1 * scale), braceDB1, ref ext, scale);
                                DimPloter.AddLRMarkRotate(db, "C", stPt1.C3D(ycurT + 4.5 * scale, -topW1 * 0.5 - 8.5 * scale), ref ext, scale, true);
                                DimPloter.AddLRMarkRotate(db, "C", stPt1.C3D(ycurT + 4.5 * scale, topW1 * 0.5 + 3.5 * scale), ref ext, scale, true);
                            }
                            one2Dim = true;
                        }
                    }
                    else
                    {
                        scaleTen = 1 / 2.000;
                        PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                        PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                        Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                        Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                        Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                        Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                        if (is_add_gemstone_fifteen == "1")
                        {
                           
                            PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                            PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                            PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                            PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);
                        }
                        if (!twoDim)
                        {
                            double le = ptRB.Y - ptLB.Y;
                            Point2d p1 = GeTools.DivPoint(ptRB.C3D(), ptRT.C3D(), 4, true).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.1 + 8 * scale), p1.C2D(3 * scale, le * 0.1 + 8 * scale), maninDB2, ref ext, scale);

                            p1 = ptBMid.C2D(0, -le * 0.35);
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(4 * scale, -le * 0.3 - 2 * scale), p1.C2D(4 * scale, -le * 0.3 - 2 * scale), crossDB2, ref ext, scale);

                            p1 = GeTools.DivPoint(ptRB.C3D(), ptTMid.C3D(), 4).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, le * 0.2 - 1 * scale), p1.C2D(3 * scale, le * 0.2 - 1 * scale), braceDB2, ref ext, scale);

                            if (is_add_gemstone_fifteen == "1")
                            {
                                p1 = GeTools.DivPoint(ptMainMidR.C3D(), ptMidR.C3D()).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, -le * 0.2), p1.C2D(3 * scale, -le * 0.2), midDB2, ref ext, scale);
                            }
                            topW1 = topW10;
                            DimPloter.AddLRMarkRotate(db, "D", stPt1.C3D(ycurT + 4.5 * scale, -topW1 * 0.5 - 7 * scale - (twHeight - cushionH) * slope), ref ext, scale, true);
                            DimPloter.AddLRMarkRotate(db, "D", stPt1.C3D(ycurT + 4.5 * scale, topW1 * 0.5 + 4 * scale + (twHeight - cushionH) * slope), ref ext, scale, true);

                            //DimPloter.AddLRMarkRotate(db, "E", stPt1.C3D((ycurT + ycurB) * 0.5 + 4.5 * scale, -topW1 * 0.5 - 6 * scale - (twHeight - cushionH) * slope), ref ext, scale, true);
                            //DimPloter.AddLRMarkRotate(db, "E", stPt1.C3D((ycurT + ycurB) * 0.5 + 4.5 * scale, topW1 * 0.5 + 4 * scale + (twHeight - cushionH) * slope), ref ext, scale, true);
                            if (one2Dim || one1Dim)
                            {
                                DimPloter.DimAli(db, stPt.C3D(ycurT, topW * 0.5 + 2 * scale), stPt.C3D(ycurT - 2000, topW * 0.5 + 2 * scale), stPt.C3D(ycurT, topW * 0.5 + 5 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter);
                                //Point2d p = ptLT.C2D(-1000, 1000 * slope);
                                Point2d p = ptLT.C2D(1000, -1000 * slope);
                                DimPloter.AddMultiMLeader(db, p, p.C2D(3 * scale, -le * 0.1 - 1 * scale), p.C2D(3 * scale, -le * 0.1 - 1 * scale), maninDB2, ref ext, scale);

                            }
                        }
                        twoDim = true;
                    }
                    PLPloter.AddLine(db, ptLB.C2D(), ptLT.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptRT.C2D(), ref ext, layerName);
                    if (i == segmentLst.Count - 1)
                    {
                        PLPloter.AddLine(db, ptRB.C2D(), ptLB.C2D(), ref ext, layerName);
                        DimPloter.DimAli(db, ptLB.C3D(), ptBMid.C3D(), ptBMid.C3D(3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                        DimPloter.DimAli(db, ptRB.C3D(), ptBMid.C3D(), ptBMid.C3D(3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                    }
                    DimPloter.DimAli(db, ptLT.C3D(), ptTMid.C3D(), ptTMid.C3D(-3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);
                    DimPloter.DimAli(db, ptRT.C3D(), ptTMid.C3D(), ptTMid.C3D(-3 * scale), ref ext, scale, "", Unit.Millimeter, Unit.Millimeter, 1);

                    DimPloter.DimRot(db, ptRT.C3D(), ptRB.C3D(), ptDim.C3D(-20 * scale), ref ext, 0, scale, "", Unit.Millimeter, Unit.Millimeter);
                }
           
        }
            if (isLM)
                DimPloter.AddLeft2RightBJ(db, "A", stPt.C3D(ycurB + 9.5 * scale,topWidth * 0.5 + ycurB * slope), ref ext, scale, 3, false);
            #endregion

            //string pierNo = dr["name"].ToString();
            //if (pierNo == "P1" && isLM)
            //{
            //    Point2d styPt1 = stpointLM.C2D(-tw * 4.5, tw * 4.5 * brslope);
            //    Point2d styPt2 = stpointLM.C2D(tw * 4.5, -tw * 4.5 * brslope);
            //    Point2d yPt1 = stpointLM.C2D(-topWidth * 0.5, -yHeight);
            //    Point2d yPt2 = stpointLM.C2D(topWidth * 0.5, -yHeight);
            //    string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();
            //    String[] yHStr = yBHeightLayout.Split('+');
            //    double hy1 = 3 * 1000, hy2 = 2.6 * 1000;
            //    if(yBHeightLayout.c)
            //    if (yHStr.Length > 0)
            //    {
            //        hy1 = Double.Parse(yHStr[0]) * 1000;
            //        if (yHStr.Length > 1)
            //            hy2 = Double.Parse(yHStr[1]) * 1000;
            //    }
            //    Point2d ybtMidPt = stpointLM.C2D(0, -yHeight + hy1 + hy2);

            //    Point3d yLastPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), 15);
            //    Point3d yLastPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), 15);

            //    Point3d yp1 = GeTools.DivPoint(yPt1.C3D(), ybtMidPt.C3D(), 4);
            //    Point3d yp2 = GeTools.DivPoint(yPt2.C3D(), ybtMidPt.C3D(), 4);
            //    PLPloter.AddLine(db, yPt1.C2D(), yLastPtL.C2D(), ref ext, layerName);
            //    PLPloter.AddLine(db, yPt2.C2D(), yLastPtR.C2D(), ref ext, layerName);
            //    PLPloter.AddLine(db, yPt1.C2D(), yp1.C2D(), ref ext, layerName);
            //    PLPloter.AddLine(db, yPt2.C2D(), yp2.C2D(), ref ext, layerName);
            //}
        }

        public static void DrawGemstoneSectionShape(Database db, Point2d stpointLM, ref Extents2d extS, double twHeight, double topWidth, double slope, double topLength, double slopeL, double brslope, System.Data.DataRow dr,out double Hs, out double Ws, string layerName = "H细线", double scale = 200)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight = string.IsNullOrWhiteSpace(dr["yshape_height"].ToString()) ? cushionH : double.Parse(dr["yshape_height"].ToString()) * 1000;
            bool one1Dim = false;
            string maninDB = "Φ" + dr["gemstone_main_diameter"].ToString() + "×" + dr["gemstone_main_thickness"].ToString();
            string braceDB = "Φ" + dr["gemstone_brace_diameter"].ToString() + "×" + dr["gemstone_brace_thickness"].ToString();
            string crossDB = "Φ" + dr["gemstone_cross_diameter"].ToString() + "×" + dr["gemstone_cross_thickness"].ToString();
            string flatDB = "Φ" + dr["gemstone_flat_brace_diameter"].ToString() + "×" + dr["gemstone_flat_brace_thickness"].ToString();
            bool one2Dim = false;
            string maninDB1 = "Φ" + dr["gemstone_ten_main_diameter"].ToString() + "×" + dr["gemstone_ten_main_thickness"].ToString();
            string braceDB1 = "Φ" + dr["gemstone_ten_brace_diameter"].ToString() + "×" + dr["gemstone_ten_brace_thickness"].ToString();
            string crossDB1 = "Φ" + dr["gemstone_ten_cross_diameter"].ToString() + "×" + dr["gemstone_ten_cross_thickness"].ToString();
            string flatDB1 = "Φ" + dr["gemstone_ten_flat_brace_diameter"].ToString() + "×" + dr["gemstone_ten_flat_brace_thickness"].ToString();
            bool twoDim = false;
            string maninDB2 = "Φ" + dr["gemstone_fifteen_main_diameter"].ToString() + "×" + dr["gemstone_fifteen_main_thickness"].ToString();
            string braceDB2 = "Φ" + dr["gemstone_fifteen_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_brace_thickness"].ToString();
            string crossDB2 = "Φ" + dr["gemstone_fifteen_cross_diameter"].ToString() + "×" + dr["gemstone_fifteen_cross_thickness"].ToString();
            string midDB2 = "Φ" + dr["gemstone_fifteen_middle_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_middle_brace_thickness"].ToString();
            string flatDB2 = "Φ" + dr["gemstone_fifteen_flat_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_flat_brace_thickness"].ToString();
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            //Extents2d ext = extS;

            double h = twHeight * 0.001 - yHeight * 0.001;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - htemp + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }

            #endregion

            topWidth = topWidth + (yHeight - cushionH) * slope * 2;
            topLength = topLength + (yHeight - cushionH) * slopeL * 2;
            double ycurT = 0;
            double ycurB = 0;

            Point2d stPt = stpointLM.C2D(0, -yHeight);
            Point2d pt = stPt.C2D(0, -10*scale);
            Extents2d extSec = new Extents2d(pt, pt);
            Extents2d ext = new Extents2d(pt, pt);
            bool isDraw = false;
            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 1000;
                ycurT = ycurB - seg * 1000;
                double topW = topWidth + ycurT * slope * 2;

                double topL = topLength + ycurT * slopeL * 2;
                double topMidW = topWidth + (ycurT + ycurB) * 0.5 * slope * 2;
                double topMidL = topLength + (ycurT + ycurB) * 0.5 * slopeL * 2;
                double bW = topWidth + ycurB * slope * 2;
                double bL = topWidth + ycurB * slopeL * 2;

                if (seg <= max)
                {
                    if (seg < min)
                    {
                        if (!one1Dim)
                        {
                            pt = pt.C2D(0, -ext.L() - 5 * scale);
                            ext = new Extents2d(pt.C2D(), pt.C2D());
                            PLPloter.AddPloy4(db, pt, topW * 0.5, topW * 0.5, topL, ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                            Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topL), pt.C3D(-topW * 0.5, -topL * 0.5)).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(2 * scale, 3 * scale), p1.C2D(2 * scale, 3 * scale), flatDB, ref ext, scale);

                            TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "B-B", "", scale);
                            isDraw = true;
                            extSec= extSec.Add(ext);
                        }
                        one1Dim = true;
                    }
                    else
                    {
                        if (!one2Dim)
                        {
                            pt = pt.C2D(0, -ext.L() - 5 * scale);
                            ext = new Extents2d(pt.C2D(), pt.C2D());
                            PLPloter.AddPloy4(db, pt, topW * 0.5, topW * 0.5, topL, ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                            Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topL), pt.C3D(-topW * 0.5, -topL * 0.5)).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(2 * scale, 3 * scale), p1.C2D(2 * scale, 3 * scale), flatDB1, ref ext, scale);
                            TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "C-C", "", scale);
                            isDraw = true;
                            extSec = extSec.Add(ext);
                        }
                        one2Dim = true;
                    }
                }
                else
                {
                    if (!twoDim)
                    {
                        pt = pt.C2D(0, -ext.L()-5*scale);
                        ext = new Extents2d(pt.C2D(), pt.C2D());
                        //if (one1Dim || one2Dim)
                        //    pt = stPt.C2D(0, -ycurT + seg * 1000 * 0.8);
                        //else
                        //    pt = stPt.C2D(0, -ycurT + seg * 1000 * 0.1);
                        PLPloter.AddPloy4(db, pt, topW * 0.5, topW * 0.5, topL, ref ext, "H细线");
                        PLPloter.AddLine(db, pt, pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                        PLPloter.AddLine(db, pt, pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                        PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(-topW * 0.5, -topL * 0.5), ref ext, layerName);
                        PLPloter.AddLine(db, pt.C2D(0, -topL), pt.C2D(topW * 0.5, -topL * 0.5), ref ext, layerName);
                        Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topL), pt.C3D(-topW * 0.5, -topL * 0.5)).C2D();
                        DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(2 * scale, 3 * scale), p1.C2D(2 * scale, 3 * scale), flatDB2, ref ext, scale);
                        TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "D-D", "", scale);
                        extSec = extSec.Add(ext);

                        pt = pt.C2D(0, -ext.L() - 5 * scale);
                        ext = new Extents2d(pt.C2D(), pt.C2D());
                        PLPloter.AddPloy4(db, pt, topMidW * 0.5, topMidW * 0.5, topMidL, ref ext, "H细线");
                        PLPloter.AddLine(db, pt.C2D(-topMidW * 0.5, -topMidL * 0.25), pt.C2D(-topMidW * 0.25, 0), ref ext, layerName);
                        PLPloter.AddLine(db, pt.C2D(topMidW * 0.5, -topMidL * 0.25), pt.C2D(topMidW * 0.25, 0), ref ext, layerName);
                        PLPloter.AddLine(db, pt.C2D(-topMidW * 0.5, -topMidL * 0.75), pt.C2D(-topMidW * 0.25, -topMidL), ref ext, layerName);
                        PLPloter.AddLine(db, pt.C2D(topMidW * 0.5, -topMidL * 0.75), pt.C2D(topMidW * 0.25, -topMidL), ref ext, layerName);
                        Point2d p2 = GeTools.MidPoint(pt.C3D(-topMidW * 0.5, -topMidL * 0.75), pt.C3D(-topMidW * 0.25, -topMidL)).C2D();
                        DimPloter.AddMultiMLeader(db, p2.C2D(), p2.C2D(2 * scale, 3 * scale), p2.C2D(2 * scale, 3 * scale), midDB2, ref ext, scale);
                        TextPloter.AddTitle(db, pt.C2D(0, 2 * scale), ref ext, "E-E", "", scale);
                        extSec = extSec.Add(ext);
                    }
                    twoDim = true;
                }

            }
            Hs = extSec.L();
            Ws= extSec.W();
            extS = extS.Add(extSec);
        }


        public static void DrawGemstoneSectionShapeRotate(Database db, Point2d stpointLM, ref Extents2d extS, double twHeight, double topWidth, double slope, double topLength, double slopeL, double brslope, System.Data.DataRow dr, out double Hs, out double Ws, string layerName = "H细线", double scale = 200)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 1000;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            double minH = twHeight, maxH = twHeight;
            string segType = "0";
            string is_add_gemstone_fifteen = "0";
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
          
         
            segType = dr["gemstone_segment_type"].ToString();
            is_add_gemstone_fifteen = dr["is_add_gemstone_fifteen"].ToString();
            //try
            //{
            //    min = int.Parse(dr["gemstone_slope"].ToString());
            //    max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            //}
            //catch { }
            double yHeight = string.IsNullOrWhiteSpace(dr["yshape_height"].ToString()) ? cushionH : double.Parse(dr["yshape_height"].ToString()) * 1000;
            try
            {
                minH = double.Parse(dr["gemstone_height"].ToString()) * 1000 - yHeight;
                maxH = double.Parse(dr["gemstone_fifteen_height"].ToString()) * 1000 - yHeight;
            }
            catch { }
            bool one1Dim = false;
            string maninDB = "Φ" + dr["gemstone_main_diameter"].ToString() + "×" + dr["gemstone_main_thickness"].ToString();
            string braceDB = "Φ" + dr["gemstone_brace_diameter"].ToString() + "×" + dr["gemstone_brace_thickness"].ToString();
            string crossDB = "Φ" + dr["gemstone_cross_diameter"].ToString() + "×" + dr["gemstone_cross_thickness"].ToString();
            string flatDB = "Φ" + dr["gemstone_flat_brace_diameter"].ToString() + "×" + dr["gemstone_flat_brace_thickness"].ToString();
            bool one2Dim = false;
            string maninDB1 = "Φ" + dr["gemstone_ten_main_diameter"].ToString() + "×" + dr["gemstone_ten_main_thickness"].ToString();
            string braceDB1 = "Φ" + dr["gemstone_ten_brace_diameter"].ToString() + "×" + dr["gemstone_ten_brace_thickness"].ToString();
            string crossDB1 = "Φ" + dr["gemstone_ten_cross_diameter"].ToString() + "×" + dr["gemstone_ten_cross_thickness"].ToString();
            string flatDB1 = "Φ" + dr["gemstone_ten_flat_brace_diameter"].ToString() + "×" + dr["gemstone_ten_flat_brace_thickness"].ToString();
            bool twoDim = false;
            string maninDB2 = "Φ" + dr["gemstone_fifteen_main_diameter"].ToString() + "×" + dr["gemstone_fifteen_main_thickness"].ToString();
            string braceDB2 = "Φ" + dr["gemstone_fifteen_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_brace_thickness"].ToString();
            string crossDB2 = "Φ" + dr["gemstone_fifteen_cross_diameter"].ToString() + "×" + dr["gemstone_fifteen_cross_thickness"].ToString();
            string midDB2 = "Φ" + dr["gemstone_fifteen_middle_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_middle_brace_thickness"].ToString();
            string flatDB2 = "Φ" + dr["gemstone_fifteen_flat_brace_diameter"].ToString() + "×" + dr["gemstone_fifteen_flat_brace_thickness"].ToString();
            Point2d pt1 = stpointLM.C2D(twHeight ,- topWidth * 0.5 - (twHeight - cushionH) * slope);
            Point2d pt2 = stpointLM.C2D(twHeight,topWidth * 0.5 + (twHeight - cushionH) * slope);
            //Extents2d ext = extS;

            double h = twHeight * 0.001 - yHeight * 0.001;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - htemp + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }

            #endregion

            topWidth = topWidth + (yHeight - cushionH) * slope * 2;
            topLength = topLength + (yHeight - cushionH) * slopeL * 2;
            double ycurT = 0;
            double ycurB = 0;

            Point2d stPt = stpointLM.C2D(yHeight);
            Point2d pt = stPt.C2D(10 * scale+ topWidth);
            Extents2d extSec = new Extents2d(pt, pt);
            Extents2d ext = new Extents2d(pt, pt);
            bool isDraw = false;
            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 1000;
                ycurT = ycurB - seg * 1000;
                double topW = topWidth + ycurT * slope * 2;

                double topL = topLength + ycurT * slopeL * 2;
                double topMidW = topWidth + (ycurT + ycurB) * 0.5 * slope * 2;
                double topMidL = topLength + (ycurT + ycurB) * 0.5 * slopeL * 2;
                double bW = topWidth + ycurB * slope * 2;
                double bL = topWidth + ycurB * slopeL * 2;

                if (segType == "0")
                {
                    if (seg <= max)
                    {
                        if (seg < min)
                        {
                            if (!one1Dim)
                            {
                                pt = pt.C2D(ext.W() + 3 * scale + topL * 0.5);
                                ext = new Extents2d(pt.C2D(), pt.C2D());
                                PLPloter.AddPloy4(db, pt, topL * 0.5, topL * 0.5, topW, ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topW), pt.C3D(-topL * 0.5, -topW * 0.5)).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(1 * scale, -topW * 0.5 - 1 * scale), p1.C2D(1 * scale, -topW * 0.5 - 1 * scale), flatDB, ref ext, scale);

                                TextPloter.AddTitleRotate(db, pt.C2D(-topL * 0.5 - 4 * scale, -topW * 0.5), ref ext, "B-B", "", scale);
                                isDraw = true;
                                extSec = extSec.Add(ext);
                            }
                            one1Dim = true;
                        }
                        else
                        {
                            if (!one2Dim)
                            {
                                pt = pt.C2D(ext.W() + 5 * scale + topL * 0.5);
                                ext = new Extents2d(pt.C2D(), pt.C2D());
                                PLPloter.AddPloy4(db, pt, topL * 0.5, topL * 0.5, topW, ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topW), pt.C3D(-topL * 0.5, -topW * 0.5)).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(1 * scale, -topW * 0.5 - 3 * scale), p1.C2D(1 * scale, -topW * 0.5 - 3 * scale), flatDB1, ref ext, scale);
                                TextPloter.AddTitleRotate(db, pt.C2D(-topL * 0.5 - 4 * scale, -topW * 0.5), ref ext, "C-C", "", scale);
                                isDraw = true;
                                extSec = extSec.Add(ext);
                            }
                            one2Dim = true;
                        }
                    }
                    else
                    {
                        if (!twoDim)
                        {
                            pt = pt.C2D(ext.W() + 5 * scale + topL * 0.5);
                            ext = new Extents2d(pt.C2D(), pt.C2D());
                            PLPloter.AddPloy4(db, pt, topL * 0.5, topL * 0.5, topW, ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                            Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topW), pt.C3D(-topL * 0.5, -topW * 0.5)).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, 2 * scale), p1.C2D(3 * scale, 2 * scale), flatDB2, ref ext, scale);
                            TextPloter.AddTitleRotate(db, pt.C2D(-topL * 0.5 - 4 * scale, -topW * 0.5), ref ext, "D-D", "", scale);
                            extSec = extSec.Add(ext);

                            pt = pt.C2D(ext.W() + 5 * scale + topMidL * 0.5); ;
                            ext = new Extents2d(pt.C2D(), pt.C2D());
                            PLPloter.AddPloy4(db, pt, topMidL * 0.5, topMidL * 0.5, topMidW, ref ext, "H细线");
                            PLPloter.AddLine(db, pt.C2D(-topMidL * 0.25, 0), pt.C2D(-topMidL * 0.5, -topMidW * 0.25), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(-topMidL * 0.25, -topMidW), pt.C2D(-topMidL * 0.5, -topMidW * 0.75), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(topMidL * 0.25, 0), pt.C2D(topMidL * 0.5, -topMidW * 0.25), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(topMidL * 0.25, -topMidW), pt.C2D(topMidL * 0.5, -topMidW * 0.75), ref ext, layerName);
                            Point2d p2 = GeTools.MidPoint(pt.C3D(-topMidL * 0.25, -topMidW), pt.C3D(-topMidL * 0.5, -topMidW * 0.75)).C2D();
                            DimPloter.AddMultiMLeader(db, p2.C2D(), p2.C2D(3 * scale, 2 * scale), p2.C2D(3 * scale, 2 * scale), midDB2, ref ext, scale);
                            TextPloter.AddTitleRotate(db, pt.C2D(-topMidL * 0.5 - 4 * scale, -topMidW * 0.5), ref ext, "E-E", "", scale);
                            extSec = extSec.Add(ext);
                        }
                        twoDim = true;
                    }

                }
                else
                {
                    if (ycurB <= maxH)
                    {
                        if (ycurB <= minH)
                        {
                            if (!one1Dim)
                            {
                                pt = pt.C2D(ext.W() + 3 * scale + topL * 0.5);
                                ext = new Extents2d(pt.C2D(), pt.C2D());
                                PLPloter.AddPloy4(db, pt, topL * 0.5, topL * 0.5, topW, ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topW), pt.C3D(-topL * 0.5, -topW * 0.5)).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(1 * scale, -topW * 0.5 - 1 * scale), p1.C2D(1 * scale, -topW * 0.5 - 1 * scale), flatDB, ref ext, scale);

                                TextPloter.AddTitleRotate(db, pt.C2D(-topL * 0.5 - 4 * scale, -topW * 0.5), ref ext, "B-B", "", scale);
                                isDraw = true;
                                extSec = extSec.Add(ext);
                            }
                            one1Dim = true;
                        }
                        else
                        {
                            if (!one2Dim)
                            {
                                pt = pt.C2D(ext.W() + 5 * scale + topL * 0.5);
                                ext = new Extents2d(pt.C2D(), pt.C2D());
                                PLPloter.AddPloy4(db, pt, topL * 0.5, topL * 0.5, topW, ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt, pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                                Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topW), pt.C3D(-topL * 0.5, -topW * 0.5)).C2D();
                                DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(1 * scale, -topW * 0.5 - 3 * scale), p1.C2D(1 * scale, -topW * 0.5 - 3 * scale), flatDB1, ref ext, scale);
                                TextPloter.AddTitleRotate(db, pt.C2D(-topL * 0.5 - 4 * scale, -topW * 0.5), ref ext, "C-C", "", scale);
                                isDraw = true;
                                extSec = extSec.Add(ext);
                            }
                            one2Dim = true;
                        }
                    }
                    else
                    {
                        if (!twoDim)
                        {
                            pt = pt.C2D(ext.W() + 5 * scale + topL * 0.5);
                            ext = new Extents2d(pt.C2D(), pt.C2D());
                            PLPloter.AddPloy4(db, pt, topL * 0.5, topL * 0.5, topW, ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt, pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(-topL * 0.5, -topW * 0.5), ref ext, layerName);
                            PLPloter.AddLine(db, pt.C2D(0, -topW), pt.C2D(topL * 0.5, -topW * 0.5), ref ext, layerName);
                            Point2d p1 = GeTools.MidPoint(pt.C3D(0, -topW), pt.C3D(-topL * 0.5, -topW * 0.5)).C2D();
                            DimPloter.AddMultiMLeader(db, p1.C2D(), p1.C2D(3 * scale, 2 * scale), p1.C2D(3 * scale, 2 * scale), flatDB2, ref ext, scale);
                            TextPloter.AddTitleRotate(db, pt.C2D(-topL * 0.5 - 4 * scale, -topW * 0.5), ref ext, "D-D", "", scale);
                            extSec = extSec.Add(ext);

                            if (is_add_gemstone_fifteen == "1")
                            {
                                pt = pt.C2D(ext.W() + 5 * scale + topMidL * 0.5); ;
                                ext = new Extents2d(pt.C2D(), pt.C2D());
                                PLPloter.AddPloy4(db, pt, topMidL * 0.5, topMidL * 0.5, topMidW, ref ext, "H细线");
                                PLPloter.AddLine(db, pt.C2D(-topMidL * 0.25, 0), pt.C2D(-topMidL * 0.5, -topMidW * 0.25), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(-topMidL * 0.25, -topMidW), pt.C2D(-topMidL * 0.5, -topMidW * 0.75), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(topMidL * 0.25, 0), pt.C2D(topMidL * 0.5, -topMidW * 0.25), ref ext, layerName);
                                PLPloter.AddLine(db, pt.C2D(topMidL * 0.25, -topMidW), pt.C2D(topMidL * 0.5, -topMidW * 0.75), ref ext, layerName);
                                Point2d p2 = GeTools.MidPoint(pt.C3D(-topMidL * 0.25, -topMidW), pt.C3D(-topMidL * 0.5, -topMidW * 0.75)).C2D();
                                DimPloter.AddMultiMLeader(db, p2.C2D(), p2.C2D(3 * scale, 2 * scale), p2.C2D(3 * scale, 2 * scale), midDB2, ref ext, scale);
                                TextPloter.AddTitleRotate(db, pt.C2D(-topMidL * 0.5 - 4 * scale, -topMidW * 0.5), ref ext, "E-E", "", scale);
                                extSec = extSec.Add(ext);
                            }
                        }
                        twoDim = true;
                    }
                }
            }
            Hs = extSec.L();
            Ws = extSec.W();
            extS = extS.Add(extSec);
        }

        #endregion
    }
}
